[英]makefile not putting the .o and executable in the respective obj and bin directories
[英]Makefile leaves .o and doesn't produce executable
我制作的makefile有問題,該makefile不產生可執行文件,並將所有.o保留在目錄中。 這是代碼:
CXXFLAGS=-Wall
sources = tst_Robot.cpp Robot.cpp Position.cpp Plot.cpp Objet.cpp EtatRobot.cpp EtatFige.cpp EtatEnRoute.cpp EtatEnChargeFacePlot.cpp EtatEnCharge.cpp EtatAVideFacePlot.cpp EtatAVide.cpp
objets = $(sources:.cpp=.o)
%: %.o
$(LINK.cpp) -o $@ $^
robot : $(objets)
###
clean:
rm -f *~ *.o *.bak
depend:
makedepend $(sources)
我不明白的是,makedepend可以正常工作,沒有錯誤,所有.o都生成,但是程序本身也沒有生成,即使使用以下規則:robot:$(objets)
所以我不明白為什么它不起作用,如果您能幫助我弄清楚它,我將不勝感激。
模式規則始終是一對文件配對的一對一匹配,例如
%.o: %.cpp
您可能會想到,模式規則只是為每對編寫單獨的規則的捷徑。 上面的規則將匹配以下對:
source.o: source.cpp
other.o: other.cpp
...
您需要制定規則如何使robot
成為目標。
robot: $(objets)
$(LINK.cpp) -o $@ $^
而且您必須刪除模式規則,因為它適用於幾乎所有情況。 如果您使用以下方式致電make:
make robot
模式規則將嘗試查找robot.o
文件,這將是構建robot的輸入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.