title: Conditional #include in C
body: <p>Is there a way to make a conditional include with the c preprocessor?</p>
  
  <p>I have a "library" of tools (Tools.c, Tools.h), shared by different teams. This library depends on a second one, providing XML-capabilities. Lets call that one XML.h Now one team uses a plain version of the second library (XML.h), while another team uses an extended version (XMLEx.h) in their project. The second team doesn't want to include the XML.h because they already have XMLEx.h included, providing all functions of XML.h.</p>
  
  <p>Is there a mechanism to implement something like:</p>
  
  <pre><code>#ifdef XML_EX
  #include "XMLEx.h"
  #else
  #include "XML.h"
  #endif
  </code></pre>
  
  <p>only with the <code>#define XML_EX</code> on a higher (project) level? Like</p>
  
  <pre><code>#include "Tools.h"
  </code></pre>
  
  <p>for Team 1 and</p>
  
  <pre><code>#define XML_EX
  #include "Tools.h"
  </code></pre>
  
  <p>for Team 2? (I know that simple solution would not work, it's more to illustrate the desired "workflow".)</p>
  
  <p>Boundary conditions are:</p>
  
  <ul>
  <li>Windows system</li>
  <li>CVI/LawWindows IDE </li>
  <li>no make files </li>
  <li>Tools.h should compile without an outer project.</li>
  </ul>
  
  <p>EDIT:
  For the suggested solution and the hint, that it is the common way, maybe it has something to do with my build process, but it doesn't work. The IDE is complaining about missing XML.h for team 2. I guess, it's because the IDE tries to compile each source standalone first, not knowing about the "outer" #define.</p>
  
  <p>EDIT:
  Let's pretend, team A is bunch of morons how could only hit the "RUN" button in the IDE. Therefore it best has to work out of the box.</p>
  
  <p>EDIT:
  Okay, it puzzled me. All I've learned tells me, it should work. Here is a minimal set, I've tested:</p>
  
  <p>main.c</p>
  
  <pre><code>#define XML_EX
  #include "Tools.h"
  
  void main(void)
  {
    test();
  }
  </code></pre>
  
  <p>then Tools.h</p>
  
  <pre><code>#ifdef XML_EX
    #include "XMLEx.h"
  #else
    #include "XML.h"
  #endif
  </code></pre>
  
  <p>XMLEx.h has the test function und XMLEx.c implements it. If I try to build, I get an "XML.h not found". Everything builds fine with a <code>#define XML_EX</code> in the Tools.h.</p>