makefile - 在 makefile 中从 g++ 切换到 clang++

标签 makefile g++ clang++

我有以下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/

相关文章:

c++ - 创建静态链接所有依赖项的共享 .so 库

makefile - 如何强制 make 始终更新并重新读取包含的 makefile?

在 Windows 上使用 Makefile 编译 C 文件

c++ - 使用 opencv 和 C++ 的链接器问题 - Undefined Reference

makefile - 覆盖makefile中的变量

ubuntu - C++0x_warning.h :31:2: error:

c++ - 对基于模板参数的模板实例化发出警告

c++ - 在//C++ 注释中使用\\是否合法? (C++ 注释中的 LaTeX 方程)

libc++ - clang++ 找不到文件 <iterator>

QtCreator 下的 clang++ 无法与 c++11 一起使用