Louis Hong
Louis Hong

Reputation: 1070

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

My template implementation is in BList.cpp, but BList.h includes BList.cpp. That's why I pass the header in as an object. I don't know how to set clang to compile!


Upvotes: 0

Views: 666

Answers (1)

The error has nothing to do with including BList.cpp in BList.h (though that's a dubious practice by itself).

The problem is that you pass src/BList.h to Clang as if it was a source file. The build instruction should be:

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

You should update your makefile accordingly.

Upvotes: 3

Related Questions