Is there a way to do conditional inclusion with c preprocessor?
I have a "library" of tools (Tools.c, Tools.h) that are used by different teams. This library depends on the second, providing XML capabilities. Let's call that one XML.h Now one team uses the simple version of the second library (XML.h), and the other team uses the extended version (XMLEx.h) in its project. The second command does not want to include XML.h, because they already contain XMLEx.h, providing all the functions of XML.h.
Is there a mechanism for implementing something like:
#ifdef XML_EX #include "XMLEx.h" #else #include "XML.h" #endif
only with #define XML_EX at a higher (project) level? how
#include "Tools.h"
for team 1 and
#define XML_EX #include "Tools.h"
for team 2? (I know that a simple solution will not work, it more illustrates the desired "workflow.")
Border conditions:
- Windows system
- CVI / LawWindows Identifier
- no make files
- Tools.h should compile without an external project.
EDIT: For the proposed solution and a hint that this is the usual way, maybe it has something to do with my build process, but it doesn't work. The IDE complains about the lack of XML.h for command 2. I think this is because the IDE tries to compile each source separately first, not knowing the "external" #define.
EDIT: Let it pretend, Team A is a bunch of morons as soon as you hit the "RUN" button in the IDE. Therefore, it is best to work out of the box.
EDIT: Okay, that puzzled me. All I found out tells me this should work. Here is the minimal set I tested:
main.c
#define XML_EX #include "Tools.h" void main(void) { test(); }
then Tools.h
#ifdef XML_EX #include "XMLEx.h" #else #include "XML.h" #endif
XMLEx.h has a testing function, and XMLEx.c implements it. If I try to build, I get "XML.h not found". Everything builds fine with #define XML_EX in Tools.h.