2

我有一个可以完美编译的项目gcc,但无法在 Greenhills Integrity 环境下编译。

问题归结为这三个文件:

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

MyVector.hpp包含向量的模板类,并MyVector.cpp包含与 的模板无关的测试函数MyVector.hpp

现在,当我在 中使用MyVector.hppvector模板时SomeFile.cpp,不知何故,该函数testVector被注入到SomeFile.cpp. 当我停止使用vectorSomeFile.cpp(当然,我仍在使用#include它,我只是没有在那里实例化模板)它工作得很好。

此外,当我在函数中注入警告testVector,编译器在编译时显示警告SomeFile.cpp

此外,SomeFile.cpp当我在MyVector.cpp.

当我testVector从中删除函数MyVector.cpp并将其移动到新函数时NewFile.cpp- 它会编译。

不,我没有cpp错误地包含该文件,老实说,我仔细检查了它,并grep编辑了我所有的源代码。

我不知道是怎么回事。我会很高兴有任何线索。

4

3 回答 3

2

Green Hills 使用 Edison Design Group 的前端,直到最近(例如,MULTI 5.0 甚至可能是 5.2)编译器--implicit_include默认打开。这是该选项的爱迪生文档

--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_includeor :compiler.args=--no_implicit_include,其中任何一个都会将选项直接传递到前端,而无需驱动程序(太多)审查。传递--stdor--STD也可能有帮助;我不记得了。)

隐含包含在今天是一个非常愚蠢的想法,但它是 90 年代提供模板功能的一种便捷方式。今天,有标准和众所周知的方法来满足单一定义规则,而这种“隐含”的技巧只会妨碍像你这样守法的 C++ 人。

现在继续,问我关于预链接的问题...... :)

于 2012-09-06T17:46:47.813 回答
-1

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

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

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

于 2011-04-12T16:57:18.307 回答
-2

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

于 2010-09-15T19:57:01.090 回答