clang++ 编译模板 class 并在 header 中实现
clang++ compiling template class with implementation in header
$ 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 作为 object 传递的原因。不知道怎么设置clang才能编译!
我的header必须按照我教授的名字命名"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。
$ 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 作为 object 传递的原因。不知道怎么设置clang才能编译!
我的header必须按照我教授的名字命名"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。