問題的原因就是我之前裝的 toolchain 裡也有提供 make 的 exe,我也有把這個 toolchain 加進 windows 的 PATH 中,結果我在 Cygwin 中做 make 時就誤用了這個 toolchain 的 make ,我應該使用的是 Cygwin installer 中提供的 make 才對。
我就把這個 toolchain 從 windows PATH 中移除後重開 Cygwin,再用一次 'whereis make' 確定 make 的路徑是 '/usr/bin/make.exe' 。重新 build code 時就沒有問題了。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
工作上有個 repo 使用 recursive make 來 build,剛接手時因為不熟悉,就先照著他的流程使用。使用的過程中發現他有個缺點,需要在每個單獨 build 的 makefile 中寫出所有需要的 include path。照 GNU make 的說明是有方法可以把參數傳進 sub makefile 中的,不過這邊沒有這樣用,這邊使用的方式是把建立 parent path 的 makefile include 進所有的 sub makefile,在依照各個 lib 的需要自己處理 header path。這樣的做法會在各 sub makefile 中發現很多重複的 header path 設定。感覺很阿雜。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
之後在 sub makefile 中就可以把 source 或者是 compile option 累加進 var 中,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
最後問題 3 的需求,主要的問題是如何跟 make 說有哪些 lib 要 build。這邊因為我是每個 sub makefile 都是一個 lib,所以就可以在每個 sub makefile 中加入下面的 rule,這樣每當 sub makefile 被 include 時,就會為每個 sub makefile 建立這個 rule 來 build 出我要的 lib。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
最近才知道 Make 有 "-j4" 這種可以做平行編譯的指令。再驚訝之餘,問題就來了,平常 compile 時都是一個個 source 在做,到底這個指令下去後,Make 是怎麼做的呢?想了解這後面的原理,感覺很厲害。
翻開 GNU Make manual,5.4 Parallel Execution 中說 make 就是知道如何平行的執行 makefile 中的 "recipe"
GNU make knows how to execute several recipes at once.
Normally, make will execute only one recipe at a time, waiting
for it to finish before executing the next. However, the ‘-j’ or
‘--jobs’ option tells make to execute many recipes
simultaneously.