title: Override macro from the command line
body: <p>I would like to override a macro from the command line. Somewhere in my source, there is a definition like this:</p>
  
  <pre><code>#define MY_FOO 1
  </code></pre>
  
  <p>What I would like is to set the value of this macro when I compile my program:</p>
  
  <pre><code>g++ -DMY_FOO=2 ...
  </code></pre>
  
  <p>But then, the macro is redefined by the source code to its old value 1. The problem is that I don't own the part of the source that defines the macro in the first place. If it were my own code, I could simply write</p>
  
  <pre><code>#ifndef MY_FOO
  #define MY_FOO 1
  #endif
  </code></pre>
  
  <p>And my problem would be gone. So is there way to specify a macro on the command line using g++ so that the source code cannot redefine it?</p>