下面这个makefile非常简单,能满足基本的项目需要,首先是一个总的target:306Please respect copyright.PENANAfq75U6EzDx
all: $(TARGET)
这个总的target由多个.o文件link而成:306Please respect copyright.PENANAx9zj5VNlaD
$(TARGET) : $(OBJECTS)306Please respect copyright.PENANA2CB94CFqAU
$(CC) -o $(TARGET) $(addprefix $(OBJ_DIR)/, $(OBJECTS)) $(CFLAGS)306Please respect copyright.PENANAe6mkXtcE2k
echo "make succeed"
每个.o文件对应一个同名的.cpp文件,加上全局的头文件,这里有3个全局的头文件,如果不加头文件,那么当头文件被修改时,.cpp不会被重新编译成.o,因此一定要加:306Please respect copyright.PENANA9ysOgxuKUo
%.o : %.cpp $(H_DIR)/01.system.h $(H_DIR)/02.01.macros.h $(H_DIR)/02.types.h306Please respect copyright.PENANAgQYaSihpXa
$(CC) -c -g $< -o $(OBJ_DIR)/$@
这样makefile就做好了,完整的内容如下:
----------makefile------------------
CC = gcc306Please respect copyright.PENANA5qEmWTTGHd
CFLAGS = -lpthread -lm -lssl -lcrypto -lzip -g306Please respect copyright.PENANAnuK2MgvsSM
306Please respect copyright.PENANA49hmDZZfTj
TARGET = buda306Please respect copyright.PENANA7vkdSXZ3xz
OBJ_DIR = ./debug/obj306Please respect copyright.PENANAb5cHqIl79B
SRC_DIR = ./src306Please respect copyright.PENANAPRQWrBcfax
H_DIR = ./includes306Please respect copyright.PENANAK1GKr1EioF
306Please respect copyright.PENANAajJH0IdXql
SRC = $(wildcard $(SRC_DIR)/*.cpp)306Please respect copyright.PENANAmwH03uAOip
OBJECTS = $(patsubst $(SRC_DIR)/%.cpp, %.o, $(SRC))306Please respect copyright.PENANA7GXZg2bwMa
306Please respect copyright.PENANATxLILIk1iZ
VPATH = $(SRC_DIR)306Please respect copyright.PENANAhftslXlPhT
vpath %.o $(OBJ_DIR)306Please respect copyright.PENANADHirZ4jZuo
306Please respect copyright.PENANAz3VigxoDU1
all: $(TARGET)306Please respect copyright.PENANAAgzY2TdnXa
306Please respect copyright.PENANAsEMMzApYc7
$(TARGET) : $(OBJECTS)306Please respect copyright.PENANAOanEt48wzJ
$(CC) -o $(TARGET) $(addprefix $(OBJ_DIR)/, $(OBJECTS)) $(CFLAGS)306Please respect copyright.PENANAYJv0UEgmJv
echo "make succeed"306Please respect copyright.PENANAIMW2GyLGeK
306Please respect copyright.PENANAiS78EqmmaZ
%.o : %.cpp $(H_DIR)/01.system.h $(H_DIR)/02.01.macros.h $(H_DIR)/02.types.h306Please respect copyright.PENANAR2rPfgyo2z
$(CC) -c -g $< -o $(OBJ_DIR)/$@
.PHONY : clean
clean:306Please respect copyright.PENANAGmFgjxhJUh
rm -rf ./debug/$(TARGET) $(TARGET) $(OBJ_DIR)/*.o ./*.o
rebuild:306Please respect copyright.PENANADXEdrKucFP
make clean306Please respect copyright.PENANAZFDjwsdjEV
make306Please respect copyright.PENANANXytDYHQnf
306Please respect copyright.PENANAYn4ObaBqln
306Please respect copyright.PENANA4zQjTBvZeC
------------------------------------
Section X. Thanks
https://blog.csdn.net/qq_38113006/article/details/112055076306Please respect copyright.PENANAjqgqqlBFO3
https://blog.csdn.net/momodosky/article/details/119857980306Please respect copyright.PENANA3naDJZCTTU
https://makefiletutorial.com/306Please respect copyright.PENANA44PgZMriAz
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]306Please respect copyright.PENANAeAsuGupZiZ
如果您发现本文有任何错误,或者对本文有好的建议,欢迎与我联系探讨,我的微信: si_jinmin, 我的email: [email protected]
如果您對C/C++ Programming, Linux, HTTP Protocol, Website Development, Vue, Git, VsCode感興趣,邀請您加入「Linux/C/C++ Website Development」微信群,請加我的微信(si_jinmin)以便拉您进群。306Please respect copyright.PENANAtgeT5EzdH2
306Please respect copyright.PENANAcW3kqngt6o


