
- Makefile 教程
- Makefile 主頁
- Makefile - 為什麼使用 Makefile?
- Makefile - 宏
- Makefile - 依賴項
- Makefile - 規則
- Makefile - 字尾規則
- Makefile - 指令
- Makefile - 重新編譯
- Makefile - 其他功能
- Makefile - 示例
- Makefile 快速指南
- Makefile - 快速指南
- Makefile - 有用資源
- Makefile - 討論
在 Makefile 中定義依賴項
最終二進位制檔案依賴於各種原始碼和源標頭檔案是很常見的。依賴項很重要,因為它們讓make瞭解任何目標的來源。考慮以下示例:
hello: main.o factorial.o hello.o $(CC) main.o factorial.o hello.o -o hello
這裡,我們告訴make hello 依賴於 main.o、factorial.o 和 hello.o 檔案。因此,每當這些物件檔案中發生變化時,make 就會採取行動。
同時,我們需要告訴make如何準備 .o 檔案。因此我們還需要像下面這樣定義這些依賴項:
main.o: main.cpp functions.h $(CC) -c main.cpp factorial.o: factorial.cpp functions.h $(CC) -c factorial.cpp hello.o: hello.cpp functions.h $(CC) -c hello.cpp
廣告