Makefile定义工程中的宏

一、介绍:

如果用make管理你的工程,在工程中有一些灵活变量,在Makefile中实现会是很方便的。

二、使用:

1. 启开关的作用:

在 Makefile 中:

CFLAGS += -DBUILD
$(CC) $(CFLAGS)

在程序中:

#ifdef BUILD
    printf("定义了宏BUILD\n");
#endif
> 定义了宏BUILD
> 

2. 启传递内容的作用:

在 Makefile 中:

CFLAGS += -DBUILD=\“string\”
$(CC) $(CFLAGS)

在程序中:

#ifdef BUILD
    printf("定义的宏的内容是%s\n",BUILD);
#endif
> string
> 

你可能感兴趣的:(makefile)