代码之家  ›  专栏  ›  技术社区  ›  Elazar Leibovich

x.cpp/x.hpp文件完整性的奇怪行为

  •  2
  • Elazar Leibovich  · 技术社区  · 14 年前

    我有一个项目,它与 gcc ,但未能在Greenhills Integrity环境下编译。

    问题归结为以下三个文件:

    MyVector.cpp // contains function testVector
    MyVector.hpp // contains template vector<>
    SomeFile.cpp
    

    MyVector.hpp 包含向量的模板类,以及 MyVector.cpp 包含一个与 肌肉组织 的模板。

    现在,当我使用 肌肉组织 vector 模板在 SomeFile.cpp 不知何故,函数 testVector 注入 一些文件 . 当我停止使用 矢量 在里面 一些文件 (我仍然 #include “当然,我并不是在那里实例化模板)它工作得很好。

    此外,当我在函数中注入一个警告时 测试向量 ,编译器显示警告 当我编译 一些文件 !

    NewFile.cpp

    cpp grep

    3 回复  |  直到 12 年前
        1
  •  2
  •   Quuxplusone    12 年前

    Green Hills使用Edison设计组前端,直到最近(比如multi 5.0甚至5.2),编译器才打开 --implicit_include 默认情况下。这里是 Edison documentation 对于该选项:

    --implicit_include
    --no_implicit_include
    -B
         Enable or disable implicit inclusion of source files as a method of
         finding definitions of template entities to be instantiated. -B is
         equivalent to --implicit_include. The default behavior is specified
         by the configuration flag DEFAULT_IMPLICIT_TEMPLATE_INCLUSION_MODE.
         See the section of this chapter on template instantiation. This
         option is valid only in C++ mode.
    

    如果你通过,你的问题很可能会解决。 --no_implicit_include 在编译器命令行上。(如果失败,请尝试 -W0,--no_implicit_include :compiler.args=--no_implicit_include 其中任何一个都将直接通过选项到前端,而不需要司机(太多)审查。经过 --std --STD 可能也有帮助;我不记得了。)

    隐式包含在今天是一个非常愚蠢的想法,但在90年代,它是提供模板功能的一种方便的方式。 One Definition Rule 而这种“隐式包含”攻击正好妨碍了像你这样的守法C++ TIZEN。

    现在继续问我 预链接 …:)

        2
  •  -1
  •   this.josh    13 年前

    当你说“注入警告”时,你在使用 #pragma 指令?一 α语用 指令应该在编译时看到,而不是在运行时看到。

    当你说函数的测试向量被注入 SomeFile.cpp '这是如何观察到的? 您是否收到一个编译器或链接器错误,说明该函数是先前定义的?

    您是为Integrity OS编译GCC还是为x86 Linux编译GCC?
    完整性的工作方式与Linux非常不同,完整性项目的类型很重要。您可以构建一个整体完整性内核或支持动态下载的完整性内核。此外,完整性C和C++运行库与Linux不同。

        3
  •  -2
  •   Tareq A. Siraj    14 年前

    你是如何实现向量的?我认为您正在myvector.cpp中实现这一点,并在myvector.hpp的末尾包含myvector.cpp。如果是这种情况,在somefile.cpp中包含myvector.hpp将在更改myvector.cpp时触发somefile.cpp的重建。我建议通过预处理器运行它,看看testVector()是从哪里包含的。