conditional compliation based on variable into makefile

喜夏-厌秋 提交于 2019-12-12 05:37:17

问题


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:


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.



来源:https://stackoverflow.com/questions/10103006/conditional-compliation-based-on-variable-into-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!