感覺好像是很初學的問題,不過我還是不知道原來這個會有關係orz

在Makefile裡記得要加dependency file

例如檔案是test.cpp, test.h, test2.cpp, test2.h 要編譯成一個執行檔

test:
    g++ -o test test.o test2.o
test.o: 
    g++ -c test.cpp
test2.o: 
    g++ -c test2.cpp

 要改成

test: test.o test2.o
    g++ -o test test.o test2.o
test.o: test.h test.cpp
    g++ -c test.cpp
test2.o: test2.h test2.cpp
    g++ -c test2.cpp

這樣就ok了~

 

當下了make test,他會去檢查dependency file,也就是test.o和test2.o,然後test.o和test2.o會各自去檢查dependency file,也就是各自的cpp和h檔。假如發現test.cpp有更改後,test.o就會重新編譯一次。以此類推,如果改了test2.h的話,就變成test2.o會重新編譯,當返回test這邊時,發現test.o和test2.o有變動過,就會重新將兩個object檔link起來,

所以如果沒加上dependency file的話,make的時候就不知道要去檢查哪個檔案是否有更新這樣。

 

參考網頁

http://ubuntuforums.org/showthread.php?t=1189999

arrow
arrow
    文章標籤
    Makefile
    全站熱搜

    卡卡 發表在 痞客邦 留言(0) 人氣()