How do I setup visual studio to register some #def

2019-02-07 17:16发布

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

3条回答
beautiful°
2楼-- · 2019-02-07 17:50

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楼-- · 2019-02-07 18:02

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

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

查看更多
祖国的老花朵
4楼-- · 2019-02-07 18:05

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>
查看更多
登录 后发表回答