c++ - clang++编译模板类并在 header 中实现

标签 c++ clang clang++

$ make
clang++ -o build/blist.exe  src/driver.cpp src/BList.h -O0 -g -Wall -Wno-unused-parameter -Wextra -Wconversion -Wold-style-cast -std=c++14 -pedantic -Wold-style-cast
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: error: cannot specify -o when generating multiple output files

我的模板实现在 BList.cpp 中,但是 BList.h 包含 BList.cpp。这就是我将 header 作为对象传递的原因。我不知道如何设置 clang 来编译!


  • 根据我的教授,我的头文件必须命名为“BList.h”

  • 这些参数可以用 GCC 编译,但不能用 Clang 编译。

最佳答案

该错误与在 BList.h 中包含 BList.cpp 无关(尽管这本身就是一种可疑的做法)。

问题是您将 src/BList.h 传递给 Clang,就好像它是一个源文件一样。构建指令应该是:

clang++ -o build/blist.exe  src/driver.cpp -O0 -g -Wall -Wno-unused-parameter -Wextra -Wconversion -Wold-style-cast -std=c++14 -pedantic -Wold-style-cast

您应该相应地更新您的 makefile。

关于c++ - clang++编译模板类并在 header 中实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44351668/

相关文章:

c++ - 为什么不同 block 中相同命名的外部局部变量在 C++ 中的编译器之间获得不同的链接?

c++ - 尝试在 Linux 上使用 Clang++ 编译 c++11 正则表达式教程时出错

c++ - CLANG vs. GNU Compilers Collection - 在 GNU 中编译但在 CLANG 中失败

c++ - 检测循环并加快求和速度

c++ - '*' token 之前的预期初始值设定项

C++ 收银机程序不使用 <string>

C++ ReSharper - 生成函数返回值/参数类型的变量

c++ - 为什么我收到 clang 警告 : no previous prototype for function 'diff'

c++ - 使用隐式可转换对象调用 move 重载函数时出现编译错误

c++ - 使用 Clang 构建 V8 并发出 LLVM IR