用于“使用预编译头部”的状态的C ++编译器宏 [英] C++ Compiler Macro for Status of "Use Precompiled Headers"

查看:204
本文介绍了用于“使用预编译头部”的状态的C ++编译器宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它有一个预定义的c ++编译器宏,我可以用来告诉,一个文件是否使用使用预编译头,创建预编译头,不使用预编译头?

It there a predefined c++ compiler macro that I can use to tell, whether a file is compiled with "Use Precompiled Headers", "Create Precompiled Headers", "Dont Use Precompiled Headers"?

请参阅@IronMensan的答案以达到此类宏的目的!

See @IronMensan 's answer for the purpose of such a macro!

推荐答案

认为有什么,虽然我当然明白一个人的愿望。每当我不得不在一个不支持PCH的系统上建立我的跨平台库,它需要永远,因为许多文件拉动的方式比他们真正需要的,这将是很好的修剪它。不幸的是我不能因为Visual Studio如何处理PCH。也就是说,包括PCH必须是文件的第一个非注释行。从你的措辞你的问题,我怀疑你也在使用Visual Studio。

I don't think there is anything, though I certainly understand the desire for one. Whenever I have to build my cross-platform library on a system that dozen't support PCH, it takes forever since a lot of files are pulling in way more than they really need and it would be nice to trim that out. Unfortunately I can't because of how Visual Studio handles PCH. Namely that the inclusion of the PCH must be the first non-comment line of the file. From the way you worded your question, I suspect that you are also working with Visual Studio.

我不知道这是否会为你工作,但你可以尝试像这:

I am not sure if this will work for you but you could try something like this:

#include MY_PCH_FILE

并在命令行中使用
/DMY_PCH_FILE=\"myfile.h

And use /DMY_PCH_FILE="myfile.h"

来控制第一个包含文件是什么。之后,您可以完全控制什么被包括和适当的头部保护以及大多数现代编译器中的优化,以检测头部保护可以减少构建时间。您可以在项目的构建设置中更改单个文件宏的定义,以类似的方式更改每个文件的PCH设置。

on the command line to control what the first include file is. After that you have full control over what gets included and proper header guards along with the optimization in most modern compilers to detect header guards could reduce build times. You can change the definition of the macro for individual file in the build settings of your project, in a similar manor to how you can change the PCH settings for each file.

虽然我必须承认,我不知道你在做什么,我怀疑这是一个 XY问题

Though I must admit that I am not sure what you are trying to do and I suspect this is really an XY problem

这篇关于用于“使用预编译头部”的状态的C ++编译器宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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