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

发布于 2024-09-19 16:47:19 字数 1018 浏览 1 评论 0原文

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

问题归结为这三个文件:

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

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

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

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

而且,构建系统重新编译< code>SomeFile.cpp 当我更改 MyVector.cpp 中的内容时。

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

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

我不知道发生了什么事。我会很高兴有任何线索。

I'm having a project which compiles perfectly with gcc, but fails to compile under Greenhills Integrity environment.

The problem boils down to this three files:

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

MyVector.hpp contains template-class for a vector, and MyVector.cpp contains a testing function unrelated to MyVector.hpp's templates.

Now, when I'm using MyVector.hpp's vector templates in SomeFile.cpp, somehow, the function testVector gets injected into SomeFile.cpp. When I cease to use vector in SomeFile.cpp (I'm still #include'ing it of course, I'm just not instantiate the template there) it works perfectly.

Moreover when I injected a warning into function testVector, the compiler showed the warning when I compiled SomeFile.cpp!

Moreover, the build system recompiles SomeFile.cpp when I'm changing things in MyVector.cpp.

When I'm deleting the testVector function from MyVector.cpp and move it to a new NewFile.cpp - it compiles.

No, I didn't include the cpp file by mistake, honest, I double checked it, and greped all my source code.

I have no idea what's going on. I'll be glad for any clue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼角的笑意。 2024-09-26 16:47:20

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

--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.

如果您通过< code>--no_implicit_include 在编译器命令行上。 (如果失败,请尝试 -W0,--no_implicit_include:compiler.args=--no_implicit_include,其中任何一个都会将选项直接传递到前端没有(太多)驱动程序的审查。通过 --std--STD 也可能有帮助;我不记得了。)

隐式包含在今天是一个非常愚蠢的想法。 ,但这是 90 年代提供模板功能的便捷方式。如今,有一些标准且众所周知的方法可以满足单一定义规则,并且这种“隐式” “包容性”黑客只会妨碍像您这样守法的 C++ 公民。

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

Green Hills uses the Edison Design Group front-end, and until very recently (say, MULTI 5.0 or maybe even 5.2) the compiler turned on --implicit_include by default. Here's the Edison documentation for that option:

--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.

Your problem will very likely be fixed if you pass --no_implicit_include on the compiler command line. (If that fails, try -W0,--no_implicit_include or :compiler.args=--no_implicit_include, either of which will pass the option straight through to the front-end without (much) censorship by the driver. Passing --std or --STD might also help; I don't remember.)

Implicit inclusion is a terribly stupid idea today, but it was a convenient way to provide template functionality back in the '90s. Today, there are standard and well-known ways of satisfying the One Definition Rule, and this "implicit inclusion" hack just gets in the way of law-abiding C++tizens such as yourself.

Now go on, ask me about prelinking... :)

溺ぐ爱和你が 2024-09-26 16:47:20

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

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

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

When you say you 'inject a warning' are you using a #pragma directive? A #pragma directive is meant to be seen during compile time, not during run time.

When you say the function 'testVector gets injected into SomeFile.cpp', how is this observed?
Do you get a compiler or linker error saying that the function was previously defined?

Are you compiling gcc for Integrity OS or gcc for x86 Linux?
Integrity works very differently from Linux, and the type of Integrity project matters. You can build a monolithic Integrity kernel or an Integrity kernel supporting dynamic download. Additionally the Integrity C and C++ runtime libraries are different from Linux.

生来就爱笑 2024-09-26 16:47:20

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

How are you implementing vector? I'm thinking you're implementing this in MyVector.cpp and including MyVector.cpp at the end of MyVector.hpp. If this is the case, including MyVector.hpp in SomeFile.cpp will trigger a rebuild of SomeFile.cpp when you change MyVector.cpp. I'd suggest run it through the pre-processor and see where the testVector() is being included from.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文