我是在Ubuntu中使用gcc的新手,所以我嘗試創建一個Makefile。我的項目文件夾被稱爲「項目」這個文件夾裏面我有三個文件夾:來源,標題,對象(空)。Makefile與不同目錄中的文件
我的Makefile應該能夠在「對象」文件夾中創建對象文件。不過,我希望我的可執行文件和Makefile位於主文件夾中:「項目」,然後我可以清除可執行文件和目標文件。 如何編譯包含這些文件夾的程序?這是我的Makefile作爲例子。文件夾「項目」位於我的主文件夾中。
CFLAGS= -ansi -pedantic -Wall -c
all: project
project: ./objects/main.o ./objects/factorial.o ./objects/gcd.o ./objects/greatestNumber.o ./objects/primeNumbers.o
gcc -o project ./objects/main.o ./objects/factorial.o ./objects/gcd.o ./objects/greatestNumber.o ./objects/primeNumbers.o
main.o: ./sources/main.c
gcc $(CFLAGS) ./sources/main.c
factorial.o: ./sources/factorial.c ./headers/factorial.h
gcc $(CFLAGS) ./sources/factorial.c
gcd.o: ./sources/gcd.c ./headers/gcd.h
gcc $(CFLAGS) ./sources/gcd.c
greatestNumber.o: ./sources/greatestNumber.c ./headers/greatestNumber.h
gcc $(CFLAGS) ./sources/greatestNumber.c
primeNumbers.o: ./sources/primeNumbers.c ./headers/primeNumbers.h
gcc $(CFLAGS) ./sources/primeNumbers.c
clean:
rm -f ./objects/main.o ./objects/factorial.o ./objects/gcd.o ./objects/greatestNumber.o ./objects/primeNumbers.o project
感謝
你確定'main.o'不依賴任何頭文件嗎? – aschepler
它依賴於gcd.h,factorial.h,greatestNumber.h,primeNumbers.h – user3654532