在不使用预编译头的 C++ 项目中编译 C 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13883686/
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
Compile C files in C++ project which do not use precompiled header?
提问by Praetorian
Can I disable precompile header for .c files in my C++ project?
我可以在我的 C++ 项目中禁用 .c 文件的预编译头文件吗?
I'm getting these errors when I want to add the .C files to my program for a scripting virtual/abstract machine which is in C:
当我想将 .C 文件添加到我的程序中以用于 C 中的脚本虚拟/抽象机器时,出现这些错误:
Error 1 error C1853: 'Release\pluginsa.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa) Z:\Profile\Rafal\Desktop\samod\source\amx\amx.c 1 1 pluginsa
错误 1 错误 C1853:'Release\pluginsa.pch' 预编译头文件来自先前版本的编译器,或者预编译头文件是 C++ 而您正在从 C 使用它(反之亦然) Z:\Profile\Rafal\Desktop \samod\source\amx\amx.c 1 1 pluginsa
All other stuff is C++ and uses my precompiled header.
所有其他东西都是 C++ 并使用我的预编译头文件。
回答by Praetorian
In the Solution Explorerwindow right click on the *.c file(s) and select Properties. Go to C / C++ -> Precompiled Headersand set the Precompiled Headeroption to Not Using Precompiled Headers.
在解决方案资源管理器窗口中右键单击 *.c 文件并选择Properties。转到C/C++ -> Precompiled Headers并将Precompiled Header选项设置为Not Using Precompiled Headers。
Also, unless you actually need precompiled headers, I'd say turn it off project-wide.
另外,除非您确实需要预编译头文件,否则我会说在项目范围内将其关闭。
Another option would be to compile your C files as C++ and keep using the precompiled headers. To do that, right click on the project name (or each .c file name), and set C / C++ -> Advanced -> Compiles Asto Compile as C++ code.
另一种选择是将 C 文件编译为 C++ 并继续使用预编译的头文件。为此,右键单击项目名称(或每个 .c 文件名),然后设置C/C++ -> Advanced -> Compiles As以Compile as C++ code。