4

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?

Mich
  • 2,357
  • 1
  • 25
  • 61
  • Possible duplicate of [Why are #ifndef and #define used in C++ header files?](https://stackoverflow.com/questions/1653958/why-are-ifndef-and-define-used-in-c-header-files) – KPCT Jun 05 '18 at 21:35
  • Yes! I gave the solution for this exact problem situation in another StackOverflow answer: https://stackoverflow.com/questions/5272556/can-you-make-a-vc-solution-set-preprocessor-defines-on-loaded-projects – librik Jun 06 '18 at 02:10

1 Answers1

1

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.

MPops
  • 350
  • 3
  • 8
  • If you force the library's build directory to be a subdirectory of the current Solution file, then it will be rebuilt over and over as it is used by different Solutions. The .lib file (or even its component .obj files) won't be shared between different uses of the library project. – librik Jun 06 '18 at 02:25