我的MakeFile模板,感觉蛮好用的,只需要更改SRCS就可以了 如果有外部依赖文件就添加到INCLUDE里面,使用的时候把前面的空格换成Tab
SRCS=main.cpp class.cpp
INCLUDE=
CC=g++
OUTPUT=main
FLAG_LINK=-g -lpthread -o $(OUTPUT)
FLAG_COMPILE=-g -c
OBJS=$(SRCS:.cpp=.o)
RM=rm
$(OUTPUT):$(OBJS)
$(CC) $(FLAG_LINK) $(OBJS)
@echo Write By ZhangEF
$(OBJS): %.o: %.cpp $(INCLUDE)
$(CC) $(FLAG_COMPILE) $<
.PHONY:clean
clean:
$(RM) $(OBJS) $(OUTPUT)
--------------------------------------------------修改如下:------------------------------
SRCS=main.cpp Demo.cpp
INCLUDE=-I/mnt/hgfs/include
CC=g++
OUTPUT=out
FLAG_LINK=-g -lpthread -o $(OUTPUT)
FLAG_COMPILE=-g -c
OBJS=$(SRCS:.cpp=.o)
RM=rm
$(OUTPUT):$(OBJS)
$(CC) $(FLAG_LINK) $(OBJS)
@echo make finished!!!
$(OBJS): %.o: %.cpp
$(CC) $(INCLUDE) $(FLAG_COMPILE) $<
.PHONY:clean
clean:
$(RM) $(OBJS) $(OUTPUT)