C++ 如何设置 Visual Studio 以在全球范围内注册一些 #defines?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5100283/
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
How do I setup visual studio to register some #defines globally?
提问by user631623
What I mean is, in each of my source files I have to insert #define NOGDI to stop windows.h from including GDI defines (since it's BITMAP define conflicts with mine).
我的意思是,在我的每个源文件中,我必须插入 #define NOGDI 以阻止 windows.h 包含 GDI 定义(因为它是 BITMAP 定义与我的冲突)。
e.g.
例如
#define NOGDI
#include <windows.h>
Unfortunately, I have to do this in every seperate source file which includes windows.h, which I do not want to do. I am using Visual Studio 2005, is there any way I can set it to #define something globally? (i.e. in all of the source files).
不幸的是,我必须在包含 windows.h 的每个单独的源文件中执行此操作,我不想这样做。我正在使用 Visual Studio 2005,有什么方法可以将其设置为全局 #define 吗?(即在所有源文件中)。
回答by tenfour
Project Settings -> C/C++ -> Preprocessor -> Preprocessor definitions
项目设置 -> C/C++ -> 预处理器 -> 预处理器定义
Here you can define symbols that are applied globally to all source code in your project.
您可以在此处定义全局应用于项目中所有源代码的符号。
回答by Mna
I had set up the needed define for whole project, as described, in Project Settings -> C/C++ -> Preprocessor -> Preprocessor definitions
我已经为整个项目设置了所需的定义,如项目设置 -> C/C++ -> 预处理器 -> 预处理器定义中所述
But nevertheless this didn't work!
但是,这并没有奏效!
Eventually it turned out that problem was in checked NoInherit checkbox, "Inherit from parent or project defaults"
最终发现问题出在选中的 NoInherit 复选框中,“从父项或项目默认值继承”
In defines' line of Preprocessor Definitions Dialog it's seen as: WIN32;_DEBUG;_WINDOWS;_MBCS;$(NoInherit)
在预处理器定义对话框的定义行中,它被视为:WIN32;_DEBUG;_WINDOWS;_MBCS;$(NoInherit)
Checked the thing back and the define finally recognized.
检查回来的东西,定义终于被认出来了。
回答by Alexander Torstling
For VS2015 I edited the .vcxproj
file and added a section such as this:
对于 VS2015,我编辑了该.vcxproj
文件并添加了如下部分:
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>MY_VARIABLE=SOMETHING</PreprocessorDefinitions>