我有以下makefile:
all: xmltest
xmltest: xmltest.cpp tinyxml2.cpp tinyxml2.h
这工作正常 - 执行后
make all
生成可执行文件“xmltest”。但是,我想将编译器切换到 clang++。所以我在文件的开头添加了这一行:
CXX=clang++
现在执行
make all
产生一个错误:clang++ xmltest.cpp tinyxml2.cpp tinyxml2.h -o xmltest
clang++.exe: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
clang++.exe: error: cannot specify -o when generating multiple output files
<builtin>: recipe for target 'xmltest' failed
make: *** [xmltest] Error 1
如何使用 解决此问题最小修改 原始make文件?
最佳答案
您不应该将头文件列为翻译单元(那些是 cpps)
您通常应该使 .h 先决条件:
xmltest.cpp: tinyxml2.h
tinyxml2.cpp: tinyxml2.h
并编译/链接翻译单元:
all: xmltest
xmltest: xmltest.cpp tinyxml2.cpp
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
IIRC 你/可能/还使用
|
将“仅依赖”项放在同一行上xmltest: xmltest.cpp tinyxml2.cpp | tinyxml2.h
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
但我现在无法检查
关于makefile - 在 makefile 中从 g++ 切换到 clang++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28110500/