有没有办法判断代码现在是否被编译为 PCH 的一部分?

编程入门 行业动态 更新时间:2024-10-08 08:34:08
本文介绍了有没有办法判断代码现在是否被编译为 PCH 的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-27 15:17:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157077.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   译为   代码   PCH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!