开发者

Is there a way to tell whether code is now being compiled as part of a PCH?

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!

Thanks,

-Ofek

[Edit:] 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.


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.


While this is not a direct answer to your question, the simplest way of solving this problem is to use the #import statement with no_implementation in the header file which is used to generate the precompiled header (usually StdAfx.h) and re-#import the header file into the source file that is used to trigger the generation of the pch with the parameter implementation_only. That way the implementation of the wrapper functions are being defined, but only in one place.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜