我有main.cpp
文件,我想爲其生成依賴文件main.d
(包含在Makefile
中)。我的電話是g++ -MM -MF src/main.d -MP -MT src/main.o src/main.cpp
。它工作正常,除非我有一些源生成器。我找到-MG
這個標誌,但它不工作,因爲我預計它工作。g ++的意外行爲-MG標誌
例如:main.cpp
包括module/mod.h
(#include "module/mod.h"
)和mod.h
包括generator/gen.h
(#include "generator/gen.h"
),則產生gen.h
。有以下結構:
-Makefile
-src
--main.cpp
--module
---mod.h
---generator
----gen.h
在Makefile
我有一個規則產生src/module/generator/gen.h
。
通過g++
依賴現有的文件生成的是正確的:
src/main.o: src/module/mod.h
但對於不存在的文件gen.h
依賴只是generator/gen.h
。
如果我在生成依賴關係之前生成這個文件,它是正確的src/module/generator/gen.h
。
g++
是否有任何其他選項可以正確生成不存在文件的依賴關係?當它不存在gen.h
產生
main.d
:
src/main.o: src/module/mod.h generator/gen.h
正確生成main.d
時gen.h
存在:
src/main.o: src/module/mod.h src/module/generator/gen.h
爲什麼沒有辦法知道真正的路徑?如果在目錄「a/b/c」中的文件是'#include「d/e.h」'文件'e.h'在'a/b/c/d/e'目錄中?所以確定'''''include的完整路徑非常容易。 – Ari 2014-09-25 18:31:45
這是因爲-I(或等分)開關 - 你可以有10個目錄進行掃描的包含文件,除非文件存在,這是不可能說肯定 – 2014-09-25 18:53:30
我建議你嘗試cmake。我不喜歡它,但它解決了這個特殊問題 - 你會明確提供這個名字threar – 2014-09-25 18:55:53