title: How to use a variable from a Makefile in #ifdef in C++ file
body: <blockquote>
  <p>Makefile</p>
  </blockquote>
  <pre><code>ifeq ($(wifiSim),1)
  WIFISIM :=1
  endif
  
  all: test.cpp
  
  test.cpp : test.o
          ./a.out
  
  test.o :
          c++ test.cpp
  </code></pre>
  <blockquote>
  <p>test.cpp</p>
  </blockquote>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {    
          #ifdef WIFISIM
                  cout &lt;&lt; &quot;Inside wifisim = 1&quot; &lt;&lt; endl;
          #else
                cout &lt;&lt; &quot;Outside wifisim = 1&quot; &lt;&lt; endl;
          #endif
  
          return 0;
  }
  </code></pre>
  <p>I want to use the <code>WIFISIM</code> in the <code>test.cpp</code>.
  I am running <code>make wifiSim=1 all</code>
  But the else is being executed in <code>test.cpp</code></p>
  <p>Is there any way I can do it without doing any changes in the way the compilation for <code>test.cpp</code> is done, because I need to use this flag WIFISIM in many files and I do not want to change the way compilation for them is being done.</p>