您的位置:首页 > 编程语言 > Qt开发

Qt中实现条件编译

2016-08-12 21:51 281 查看
//test.pro
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.c

DEFINES += **Home**
#DEFINES += Ultimate

include(deployment.pri)
qtcAddDeployment()


#include <stdio.h>

#ifdef Home
#define LOG(s) printf("[%s: %d] %s",__FILE__,__LINE__,s)
#else
#define LOG(s) NULL
#endif

#ifdef Ultimate
void f()
{
printf("This is Ultimate version\n");
}
#else
void f()
{

}
#endif

int main(void)
{
LOG("Enter main...\n");

f();
printf("1.Hi.\n");
printf("2.Hello.\n");

#ifdef Ultimate
printf("3.Bye.\n");
printf("4.See U.\n");
#else
printf("3.GoodBye.\n");
#endif

LOG("Exit main...\n");

return 0;
}


输出:

[..\test\main.c: 23] Enter main…

1.Hi.

2.Hello.

3.GoodBye.

[..\test\main.c: 36] Exit main…

若修改test.pro中的

//test.pro
...
#DEFINES += Home
DEFINES += Ultimate
...


则输出为:

This is Ultimate version

1.Hi.

2.Hello.

3.Bye.

4.See U.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: