1 CUR_DIR = $(shell pwd) 2 3 CFLAGS = -g -Wall 4 GCC = gcc 5 GXX = g++ 6 7 TARGET = exe.out 8 9 SRC_FILES += $(shell find $(CUR_DIR) -name *.cc) 10 += $(shell find $(CUR_DIR) -name *.cpp) 11 12 OBJS = fatal-impl.o log.o 13 14 INCLUDE += -I. 15 RM = rm -f 16 17 LINK = 18 CFLAGS = -DNS3_LOG_ENABLE -g -Wall -O0 19 20 all: $(OBJS) test.o 21 $(GXX) $(CFLAGS) $^ -o $(TARGET) $(LINK) 22 23 test.o: test.cpp 24 $(GXX) -c $(CFLAGS) $^ -o $@ 25 26 $(OBJS): %.o : %.cc 27 $(GCC) -c $(CFLAGS) $(INCLUDE) $< -o $@ 28 29 .PHONY : clean 30 clean: 31 $(RM) $(OBJS) 32 $(RM) $(TARGET)
上面-D选项放在-c选项前宏定义不起作用,修改放在-c选项后面后ok,
相当于在需要编译的文件最开始位置添加#define xxx