C++ 在 VC++ 2010 项目中禁用特定文件的预编译头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9318951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 12:39:34  来源:igfitidea点击:

Disabling precompiled headers for a specific file in a VC++ 2010 project

c++cvisual-c++windows-7-x64

提问by bitterman

As the title says. I have a C++ project, and added 1 C .h file and a C .c source file, but they are having problems because the rest of the project uses a precompiled header, but if I try to include it in those C files, it gives an error. I can't just disable precompiled headers for the whole project, because it's part of a larger project that uses it and has code by somebody else.

正如标题所说。我有一个 C++ 项目,并添加了 1 个 C .h 文件和一个 C .c 源文件,但它们有问题,因为项目的其余部分使用预编译头文件,但是如果我尝试将它包含在那些 C 文件中,它给出一个错误。我不能只是禁用整个项目的预编译头文件,因为它是使用它的更大项目的一部分,并且有其他人的代码。

So is there a way to select those two C files (the .h header and .c source files) and disable PCH?

那么有没有办法选择这两个 C 文件(.h 头文件和 .c 源文件)并禁用 PCH?

Thanks.

谢谢。

回答by Mark Ransom

Highlight the file in the Solution Explorer and hit Alt+F7. This will bring up the properties for the file; in the "C/C++" section under "Precompiled Headers" you'll find the relevant options. You don't need to worry about the .h files.

在解决方案资源管理器中突出显示该文件并点击Alt+ F7。这将调出文件的属性;在“预编译头文件”下的“C/C++”部分,您将找到相关选项。您无需担心 .h 文件。

回答by Nathan Monteleone

In C++ at least, you can right click on the cpp file itself and hit properties -- this lets you override C/C++ compiler settings for that file only. You can use that to disable precompiled headers for that one file.

至少在 C++ 中,您可以右键单击 cpp 文件本身并点击属性——这允许您仅覆盖该文件的 C/C++ 编译器设置。您可以使用它来禁用该文件的预编译头。