Makefile 檔案 -只有include和src資料夾 (自己用)
阿新 • • 發佈:2018-11-26
檔案目錄樹結構為:
[email protected]:/home# tree
.
├── include
│ ├── client.h
│ ├── gps_module.h
│ └── jt.h
├── Makefile
└── src
├── client.c
├── gps_module.c
└── jt.c
2 directories, 7 files
[email protected]:/home#
Makefile檔案原始碼為:
#編譯器 cc = gcc #目標檔案 prom = client #編譯引數(程式中使用了多執行緒,所以使用lpthread) CFLAGS = -lpthread #原始檔 src = $(shell find ./src/ -name "*.c") #中間檔案 obj = $(prom).o #根據中間檔案編譯生成 目標檔案 $(prom): $(obj) $(cc) $(obj) -o $(prom) $(CFLAGS) #根據原始檔生成 中間檔案 $(obj): $(src) $(cc) -c $(src) #clean clean: rm -rf $(prom) *.o
編譯過程:
[email protected]:/home# ls include Makefile src [email protected]:/home# make gcc -c ./src/client.c ./src/jt.c ./src/gps_module.c lgcc client.o -o client -lpthread [email protected]:/home# ls client client.o gps_module.o include jt.o Makefile src [email protected]:/home#
寫的不是很規範(自己的程式可以將就用)大家酌情參考。