下面这个makefile非常简单,能满足基本的项目需要,首先是一个总的target:104Please respect copyright.PENANA5TNt0VFWRq
all: $(TARGET)
这个总的target由多个.o文件link而成:104Please respect copyright.PENANAotE8m6N7JR
$(TARGET) : $(OBJECTS)104Please respect copyright.PENANAag2xBplgOw
$(CC) -o $(TARGET) $(addprefix $(OBJ_DIR)/, $(OBJECTS)) $(CFLAGS)104Please respect copyright.PENANACesAeYx6L7
echo "make succeed"
每个.o文件对应一个同名的.cpp文件,加上全局的头文件,这里有3个全局的头文件,如果不加头文件,那么当头文件被修改时,.cpp不会被重新编译成.o,因此一定要加:104Please respect copyright.PENANAnIYpCzrrhU
%.o : %.cpp $(H_DIR)/01.system.h $(H_DIR)/02.01.macros.h $(H_DIR)/02.types.h104Please respect copyright.PENANAUOxfrWRU39
$(CC) -c -g $< -o $(OBJ_DIR)/$@
这样makefile就做好了,完整的内容如下:
----------makefile------------------
CC = gcc104Please respect copyright.PENANAptx7lc8oHD
CFLAGS = -lpthread -lm -lssl -lcrypto -lzip -g104Please respect copyright.PENANAXtgTqtRnIh
104Please respect copyright.PENANA3jtvARKQ9A
TARGET = buda104Please respect copyright.PENANAmt7nI3Q9ze
OBJ_DIR = ./debug/obj104Please respect copyright.PENANASWFV7bjI87
SRC_DIR = ./src104Please respect copyright.PENANAVv2JC8phrO
H_DIR = ./includes104Please respect copyright.PENANAvM0SxYtvUR
104Please respect copyright.PENANA330kOQVv13
SRC = $(wildcard $(SRC_DIR)/*.cpp)104Please respect copyright.PENANA64Sc2YPIJA
OBJECTS = $(patsubst $(SRC_DIR)/%.cpp, %.o, $(SRC))104Please respect copyright.PENANANzp8mcOQuw
104Please respect copyright.PENANAGMNjlkrDhO
VPATH = $(SRC_DIR)104Please respect copyright.PENANApe59CjDfHB
vpath %.o $(OBJ_DIR)104Please respect copyright.PENANA0NFKWX3Qo6
104Please respect copyright.PENANAquj6j4ZriM
all: $(TARGET)104Please respect copyright.PENANA27HoS7THxK
104Please respect copyright.PENANA0NPVrPLje6
$(TARGET) : $(OBJECTS)104Please respect copyright.PENANAio5Q9yf01E
$(CC) -o $(TARGET) $(addprefix $(OBJ_DIR)/, $(OBJECTS)) $(CFLAGS)104Please respect copyright.PENANATQjYBqKlo9
echo "make succeed"104Please respect copyright.PENANAFRZrga6BeJ
104Please respect copyright.PENANAYM2P3TMcgH
%.o : %.cpp $(H_DIR)/01.system.h $(H_DIR)/02.01.macros.h $(H_DIR)/02.types.h104Please respect copyright.PENANAOUIGux94s6
$(CC) -c -g $< -o $(OBJ_DIR)/$@
.PHONY : clean
clean:104Please respect copyright.PENANABJLPjammZs
rm -rf ./debug/$(TARGET) $(TARGET) $(OBJ_DIR)/*.o ./*.o
rebuild:104Please respect copyright.PENANA568UsSBuKo
make clean104Please respect copyright.PENANAyVnCrcJtKc
make104Please respect copyright.PENANADpy4SM4EyR
104Please respect copyright.PENANAPQLiQW7t3Z
104Please respect copyright.PENANATddvL9LvDF
------------------------------------
Section X. Thanks
https://blog.csdn.net/qq_38113006/article/details/112055076104Please respect copyright.PENANAJS8B5dvQql
https://blog.csdn.net/momodosky/article/details/119857980104Please respect copyright.PENANA1hcOqzlqzw
https://makefiletutorial.com/104Please respect copyright.PENANAOcLfZfKMTA
https://makefiletutorial.com/#makefile-cookbook
Section Y. Contacts Me
If you found any errors or have any suggestions for this article, please let me know, my wechat: si_jinmin, my email: [email protected]104Please respect copyright.PENANAoYYxLV46KC
如果您发现本文有任何错误,或者对本文有好的建议,欢迎与我联系探讨,我的微信: si_jinmin, 我的email: [email protected]
如果您對C/C++ Programming, Linux, HTTP Protocol, Website Development, Vue, Git, VsCode感興趣,邀請您加入「Linux/C/C++ Website Development」微信群,請加我的微信(si_jinmin)以便拉您进群。104Please respect copyright.PENANAQZDGAWvAwH
104Please respect copyright.PENANARd08m6OOO4