首页 > 解决方案 > How can I use different #defines for one project used by two different solutions without creating new configurations

问题描述

This is for Visual Studio 2015, C++

I have one project that is compiled as a library and has some #if - #else statements

#ifdef DXTK
  //...
#elif defined DXUT
  //...
#else
  //...
#endif

I have two different solutions (with a separate executable project each) that both include this library as a project.

I need to #define DXUT in one executable project and #define DXTK in the other

But the problem is, my definitions in pre-processor for the executable projects (not the library) do not affect the library project's #if - #else statements

I know one recommendation is to create different configurations for the library project and use one in one solution, and another in the other.

But is there a way to pass the preprocessor definition in the entire solution?

I tried adding /DDXUT to C/C++ -> Command Line for the executable projects, but it did not work.

How can I do this without creating a new configuration for each project?

标签: c++visual-studio-2015

解决方案


Possible duplicate of this: Are Preprocessor Definitions compiled into a library?

Short answer is No, you cannot do what you want to do without different configurations, as the code that is compiled into that library has been transformed before you even include the library into a different project.


推荐阅读