有没有办法判断代码现在是否被编译为 PCH 的一部分? [英] Is there a way to tell whether code is now being compiled as part of a PCH?

查看:23
本文介绍了有没有办法判断代码现在是否被编译为 PCH 的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据 .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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆