下面这个makefile非常简单,能满足基本的项目需要,首先是一个总的target:64Please respect copyright.PENANA0CsSiIoqE7
all: $(TARGET)
这个总的target由多个.o文件link而成:64Please respect copyright.PENANAHgCodW1oc6
$(TARGET) : $(OBJECTS)64Please respect copyright.PENANA9gGUJ62rIV
$(CC) -o $(TARGET) $(addprefix $(OBJ_DIR)/, $(OBJECTS)) $(CFLAGS)64Please respect copyright.PENANAicGnlheN2I
echo "make succeed"
每个.o文件对应一个同名的.cpp文件,加上全局的头文件,这里有3个全局的头文件,如果不加头文件,那么当头文件被修改时,.cpp不会被重新编译成.o,因此一定要加:64Please respect copyright.PENANAo4U6go1P9D
%.o : %.cpp $(H_DIR)/01.system.h $(H_DIR)/02.01.macros.h $(H_DIR)/02.types.h64Please respect copyright.PENANANMon4oDDi9
$(CC) -c -g $< -o $(OBJ_DIR)/$@
这样makefile就做好了,完整的内容如下:
----------makefile------------------
CC = gcc64Please respect copyright.PENANA5ueDupN6Eh
CFLAGS = -lpthread -lm -lssl -lcrypto -lzip -g64Please respect copyright.PENANAlaXYAABCYf
64Please respect copyright.PENANAIYpZ75BUAV
TARGET = buda64Please respect copyright.PENANAdRvkonUuUA
OBJ_DIR = ./debug/obj64Please respect copyright.PENANAtirpmDyu4o
SRC_DIR = ./src64Please respect copyright.PENANAClXIJX02X5
H_DIR = ./includes64Please respect copyright.PENANAdAMe7ucqW2
64Please respect copyright.PENANA3LQnUSJ1LP
SRC = $(wildcard $(SRC_DIR)/*.cpp)64Please respect copyright.PENANAFugWfm7kD2
OBJECTS = $(patsubst $(SRC_DIR)/%.cpp, %.o, $(SRC))64Please respect copyright.PENANAhtfGcJXkCP
64Please respect copyright.PENANACTk7welOB8
VPATH = $(SRC_DIR)64Please respect copyright.PENANAI2cJtzgBX3
vpath %.o $(OBJ_DIR)64Please respect copyright.PENANAMuZAAnwIlg
64Please respect copyright.PENANAw1IhOVS3wf
all: $(TARGET)64Please respect copyright.PENANAAllFQjFz4J
64Please respect copyright.PENANAe8HHPDXgX3
$(TARGET) : $(OBJECTS)64Please respect copyright.PENANA9NXgPJot1K
$(CC) -o $(TARGET) $(addprefix $(OBJ_DIR)/, $(OBJECTS)) $(CFLAGS)64Please respect copyright.PENANAraqIN6RFOe
echo "make succeed"64Please respect copyright.PENANA1KVhnzAoaN
64Please respect copyright.PENANAv2M3pzhb0R
%.o : %.cpp $(H_DIR)/01.system.h $(H_DIR)/02.01.macros.h $(H_DIR)/02.types.h64Please respect copyright.PENANAALvqlmT8K5
$(CC) -c -g $< -o $(OBJ_DIR)/$@
.PHONY : clean
clean:64Please respect copyright.PENANAKOVKJBfWtt
rm -rf ./debug/$(TARGET) $(TARGET) $(OBJ_DIR)/*.o ./*.o
rebuild:64Please respect copyright.PENANACOo8nq9zPR
make clean64Please respect copyright.PENANAZnrwImzk8u
make64Please respect copyright.PENANAU2oGRGnDbX
64Please respect copyright.PENANAGwVvGfCV1U
64Please respect copyright.PENANARZprdoIBma
------------------------------------
Section X. Thanks
https://blog.csdn.net/qq_38113006/article/details/11205507664Please respect copyright.PENANApMk63mjyIZ
https://blog.csdn.net/momodosky/article/details/11985798064Please respect copyright.PENANAubTKqaoYBx
https://makefiletutorial.com/64Please respect copyright.PENANATlzu6kwS4w
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]64Please respect copyright.PENANAAM60V2lZ5O
如果您发现本文有任何错误,或者对本文有好的建议,欢迎与我联系探讨,我的微信: si_jinmin, 我的email: [email protected]
如果您對C/C++ Programming, Linux, HTTP Protocol, Website Development, Vue, Git, VsCode感興趣,邀請您加入「Linux/C/C++ Website Development」微信群,請加我的微信(si_jinmin)以便拉您进群。64Please respect copyright.PENANAMA6YweNsci
64Please respect copyright.PENANAH57vEbnccU