$ 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/