如何在 Intel C++ 上获取 __FILE__ 作为绝对路径编译器

发布于 2024-09-18 05:37:46 字数 196 浏览 4 评论 0原文

我尝试使用与 Visual Studio 一起使用的 /Fc 标志,但收到一条消息,指出英特尔编译器无法识别它。

我正在尝试编写一个测试,该测试使用相对于 cpp 测试文件的目录中的数据,但是可执行文件将部署在其他地方,因此很难将其相对于 exe 获取...因此我想要一个绝对路径编译时间!我还能如何获得相对于当前 cpp 文件的路径?

I've tried using the /Fc flag which works with visual studio but get a message that it isn't recognized by the intel compiler.

I'm trying to write a test which uses data from a directory relative to the cpp test file, however the executable will be deployed elsewhere so it's hard to get it relative to the exe... hence I'd like an absolute path at compile time! How else could I get a path relative to the current cpp file?

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

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

发布评论

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

评论(2

烏雲後面有陽光 2024-09-25 05:37:46

这显然是英特尔编译器中的一个错误,它默默地接受然后忽略应该触发绝对路径的 /FC 标志。我能找到的最好的解决办法来自我在英特尔论坛上重新开始的这个线程:

要让 __FILE__ 生成绝对路径,它必须位于头文件中,该头文件已通过“附加包含目录”包含在内,该头文件必须是绝对路径。

例如,创建一个文件 test.h,该文件位于目录“test_include”中,该目录无法从包含路径直接访问,然后在包含该文件时使用:

#include "test.h"

并确保在“附加包含目录”部分中将该目录指定为绝对路径,您可能需要对宏进行一些摆弄...我的包含行如下所示:

"$(InputDir)..\include\test_include"

This is apparently a bug in the Intel Compiler, it silently accepts and then ignores the /FC flag which should trigger absolute paths. The best work around I can find came from this thread that I started over at Intel forums:

To get __FILE__ to generate an absolute path it has to be in a header file which has been included via the "Additional Include Directories" which must be an absolute path.

For example create a file test.h which is in a directory "test_include" which isn't directly accessible from your include path, then when including the file use:

#include "test.h"

and make sure that the directory is specified in your Additional Include Directory section as an absolute path, you might have to do some fiddling with the macros... my include line looks like this:

"$(InputDir)..\include\test_include"
你爱我像她 2024-09-25 05:37:46

您尝试过__BASE_FILE__吗?

它记录在 http: //software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/cpp/lin/main_cls_lin.pdf 第 170 页。它不是 ANSI 标准,但 gcc 也支持它。通过一些肮脏的#ifdef技巧,您可以设法使其适用于所有编译器。

不幸的是,我没有英特尔编译器来检查它。

Did you try out __BASE_FILE__?

It is documented in http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/cpp/lin/main_cls_lin.pdf on page 170. It is not ANSI standard but gcc also supports it. With some dirty #ifdef tricks you can manage to make it work for all compilers.

I have no Intel Compiler to check it, unfortunately.

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