Search code examples
c++buildc-preprocessorbjam

Include header files optionally in C++


I have a C++ code which needs to include a certain library in some servers and not in other servers. I build my code using bjam.

Code example:

if server in server_list:
   include <header-file.h>
   int function();
else:
   int function();

And during build using bjam:

if server in server_list:
    -llibrary
else:
   ...

Solution

  • Header file inclusion is a compile time activity not run time. So you can't use if conditions for the same

    use #ifdefs

    #define SERVER_IN_LIST
    
    #ifdef SERVER_IN_LIST
        #include<...>
    #endif