gpt4 book ai didi

c++ - Integrity 中 X.cpp/X.hpp 文件的奇怪行为

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:03:43 29 4
gpt4 key购买 nike

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

问题归结为这三个文件:

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

MyVector.hpp 包含 vector 的模板类,MyVector.cpp 包含与 MyVector.hpp 无关的测试函数模板。

现在,当我在 SomeFile.cpp 中使用 MyVector.hppvector 模板时,函数 testVector 被注入(inject)到 SomeFile.cpp 中。当我停止在 SomeFile.cpp 中使用 vector 时(我当然还在 #include 中,我只是没有实例化那里的模板)它完美地工作。

此外,当我向函数 testVector 中注入(inject)警告时,编译器在我编译 SomeFile.cpp 时显示了警告!

此外,当我更改 MyVector.cpp 中的内容时,构建系统会重新编译 SomeFile.cpp

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

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

我不知道发生了什么。我很乐意提供任何线索。

最佳答案

Green Hills 使用 Edison Design Group 前端,直到最近(比如 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++ 用户。

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

关于c++ - Integrity 中 X.cpp/X.hpp 文件的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3719675/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com