问题描述
限时送ChatGPT账号..我需要根据 .h 现在是否用于创建 PCH(即,包含在使用/Yc),或者现在包含只是为了使用 PCH(即包含在用/Yu 编译的 cpp 中).
I need to branch a certain statement in a precompiled-header .h file, based on whether the .h is now being used to create the PCH (i.e., included in a cpp compiled with /Yc), or now included just to use the PCH (i.e., included in a cpp compiled with /Yu).
换句话说,我正在寻找类似 -
In other words, I'm looking for something like -
#ifdef NOW_CREATING_THE_PCH
#import yadayada_with_option_a
#else
#import yadayada_with_option_b
#endif
...并且找不到任何东西.任何想法将不胜感激!
...and can't find anything. Any ideas would be appreciated!
谢谢,
-Ofek
我需要这个的原因是我使用 Incredibuild,并且已经开始获得 这个警告.根据常见问题解答建议,我希望使用 #importno_implementation 在 PCH 创建期间,以及 仅在 PCH 使用期间实施.
The reason I need this is that I use Incredibuild, and have started getting this warning. Per the FAQ suggestion, I wish to #import with no_implementation during PCH creation, and with implementation_only during PCH usage.
推荐答案
您可以专门更改 stdafx.cpp(或使用/Yc 编译的任何源文件)的配置(在 Visual Studio 中)来定义符号NOW_CREATING_THE_PCH,其余源文件(使用/Yu 编译)的符号未定义.
You can specifically change the configuration (in Visual Studio) of stdafx.cpp (or whatever source file you have that gets compiled with /Yc) to define the symbol NOW_CREATING_THE_PCH, leaving the symbol undefined for the rest of the source files (which get compiled with /Yu).
这不是开箱即用的东西,但如果您只需要为一个(或几个)项目执行此操作,这不是问题.
That's not something you get out-of-the-box, but if you need to do it just for one project (or a few), it's not a problem.
这篇关于有没有办法判断代码现在是否被编译为 PCH 的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论