几个makefile文件的例子
程序在不同路径
A
Main:Main.o Manager.o Reader.o Book.o g++ Main.o Parts/Manager.o Parts/Reader.o Parts/Book.o -o Main Main.o:Main.cpp g++ Main.cpp -c -Wall -g -o Main.o Manager.o: cd Parts;make Reader.o: cd Parts;make Book.o: cd Parts;make clean: rm *.o Main -rf clean_o: rm *.o
B
Manager.o:Manager.cpp Book.o Reader.o g++ -c Manager.cpp -Wall -g Book.o Reader.o -o Manager.o Reader.o:Reader.cpp g++ -c Reader.cpp -Wall -g -o Reader.o Book.o:Book.cpp g++ -c Book.cpp -Wall -g -o Book.o clean: rm *.o Main -rf clean_o: rm *.o # g++ -o Main Main.cpp Parts/Book.cpp Parts/Manager.cpp Parts/Reader.cpp
相同路径
Main:Main.o Time.o g++ Main.o Time.o -o Main Main.o:Main.cpp g++ Main.cpp -c -Wall -g -o Main.o Time.o:Time.cpp g++ Time.cpp -c -Wall -g -o Time.o clean: rm *.o Main -rf