在Makefile中定义一个宏需这样这样执行
$(CC) $(CFLAGS) $^ -o $@
main.c文件如下
#include <stdio.h>
int main()
{
#ifdef _YUQIANG
printf("Hell Yuqiang \n");
#else
printf("Sorry to lost you \n");
#endif
}
Makefile文件如下
C = gcc
RM = rm
CFLAGS+=-D _YUQIANG
TARGETS := myapp
all:$(TARGETS)
$(TARGETS):main.c
$(CC) $(CFLAGS) $^ -o $@
clean:
-$(RM) -f *.o
-$(RM) -f $(TARGETS)
make执行
makeclean 清除