基于变量的条件补全到makefile中 [英] conditional compliation based on variable into makefile

查看:136
本文介绍了基于变量的条件补全到makefile中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

此刻我使用这个:

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

这使我可以确定平台是否为32/64位,但没有给我足够的自由度.

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

我想像

make includeMyLib=1

并依赖于此,例如:

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

您知道这样的事情是否可能吗?

Do you know if anything like this is possible?

推荐答案

如果使用GNU make,在Makefile中可能会有类似的内容:

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

ifdef includeMyLib
CFLAGS += -DincludeMyLib
endif

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

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

这篇关于基于变量的条件补全到makefile中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆