title: How can I access the define macro in the header file from other files with Conditional Compilation?
body: <p>I have a macro in a header file:</p>
  <p>header.h</p>
  <pre><code>#ifndef HEADER_H
  #define HEADER_H
  
  #define vulkan
  
  #endif
  </code></pre>
  <p>I want to use this macro with <code>#ifdef</code> from other headers and sources files.</p>
  <p>game.h</p>
  <pre><code>#ifndef GAME_H
  #define GAME_H
  
  #include &quot;header.h&quot;
  
  #ifdef vulkan
  //use vulkan api
  #else
  //use opengl api
  #endif
  
  #endif
  </code></pre>
  <p>I also want to use <code>#ifdef</code> in the <code>game.cpp</code> source file, but I can't reach the <code>vulkan</code> macro with <code>#ifdef</code>, neither from the header nor from the source. What is the right way to do this?</p>
  <p><strong>EDIT</strong>: I am uploading pictures:</p>
  <p>header.h</p>
  <p><a href="https://i.stack.imgur.com/AVj57.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AVj57.png" alt="Image" /></a></p>
  <p>game.h</p>
  <p><a href="https://i.stack.imgur.com/lGYoy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lGYoy.png" alt="Image" /></a></p>
  <p>game.cpp</p>
  <p><a href="https://i.stack.imgur.com/gffGM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gffGM.png" alt="Image" /></a></p>
  <p><strong>EDIT 2</strong>: minimal reproducible example:</p>
  <p>header.h</p>
  <p><a href="https://i.stack.imgur.com/NEHbL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NEHbL.png" alt="Image" /></a></p>
  <p>game.h</p>
  <p><a href="https://i.stack.imgur.com/zLYTn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zLYTn.png" alt="Image" /></a></p>
  <p>game.cpp</p>
  <p><a href="https://i.stack.imgur.com/IZmQu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IZmQu.png" alt="Image" /></a></p>
  <p>main.cpp</p>
  <p><a href="https://i.stack.imgur.com/nmC1V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nmC1V.png" alt="Image" /></a></p>
  <p><strong>EDIT 3</strong>: here is the code:</p>
  <p>header.h</p>
  <pre><code>#ifndef HEADER_H
  #define HEADER_H
  
  #define macro
  
  #endif
  </code></pre>
  <p>game.h</p>
  <pre><code>#ifndef GAME_H
  #define GAME_H
  
  #include &quot;header.h&quot;
  
  class game
  {
  public:
  
  
      #ifdef macro
      int test;
      #else
      int test;
      #endif
  
  
  
      void init();
  };
  
  #endif
  </code></pre>
  <p>game.cpp</p>
  <pre><code>#include &quot;header.h&quot;
  #include &quot;game.h&quot;
  
  void game::init()
  {
      #ifdef macro
      int test;
      #else
      int test;
      #endif
  }
  </code></pre>
  <p>main.cpp</p>
  <pre><code>#include &quot;header.h&quot;
  #include &quot;game.h&quot;
  
  int main()
  {
      game g;
  
      g.init();
  }
  </code></pre>