基于变量的条件编译到makefile中

时间:2012-04-11 09:10:42

标签: include makefile conditional-compilation

在我的C / C ++代码中,我想根据不同的编译包含或不包含文件。

目前我用这个:

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

这让我有可能做出平台是否为32/64位,但没有给我足够的自由。

我想将变量传递给我的makefile,如

make includeMyLib=1

并且取决于具有以下内容:

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

你知道这样的事情是否可行?

1 个答案:

答案 0 :(得分:2)

如果你使用GNU make,你可以在Makefile

中使用这样的东西
ifdef includeMyLib
CFLAGS += -DincludeMyLib
endif

这将更改编译器用于添加#define includeMyLib的标记。

相关问题