How do I setup visual studio to register some #defines globally?

别来无恙 提交于 2019-12-18 12:45:45

问题


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).

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).


回答1:


Project Settings -> C/C++ -> Preprocessor -> Preprocessor definitions

Here you can define symbols that are applied globally to all source code in your project.




回答2:


I had set up the needed define for whole project, as described, in Project Settings -> C/C++ -> Preprocessor -> Preprocessor definitions

But nevertheless this didn't work!

Eventually it turned out that problem was in checked NoInherit checkbox, "Inherit from parent or project defaults"

In defines' line of Preprocessor Definitions Dialog it's seen as: WIN32;_DEBUG;_WINDOWS;_MBCS;$(NoInherit)

Checked the thing back and the define finally recognized.




回答3:


For VS2015 I edited the .vcxproj file and added a section such as this:

<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
  <ItemDefinitionGroup>
    <ClCompile>      
      <PreprocessorDefinitions>MY_VARIABLE=SOMETHING</PreprocessorDefinitions>


来源:https://stackoverflow.com/questions/5100283/how-do-i-setup-visual-studio-to-register-some-defines-globally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!