conditional compliation based on variable into mak

2019-09-07 21:26发布

Inside my C/C++ code I would like to include or not a file depending on different compilation.

For the moment I use this:

#ifndef __x86_64__
    #include <myLib.h>
#endif

this gives me the possibility of doing whether the platform is 32/64 bit but does not give me enough freedom.

I would like to pass a variable to my makefile like

make includeMyLib=1

and depending on this having something like:

#ifndef includeMyLib
    #include <myLib.h>
#endif

Do you know if anything like this is possible?

1条回答
倾城 Initia
2楼-- · 2019-09-07 22:02

If you use GNU make, you could have something like this in the Makefile:

ifdef includeMyLib
CFLAGS += -DincludeMyLib
endif

This will change the flags used by the compiler to add the #define includeMyLib.

查看更多
登录 后发表回答