In my environmental, clang and clang++ are all symbolic links to clang-12. And if I use -DCMAKE_CXX_COMPILER=clang++, my C++ codes will linked to stdc++ without problem, but if I use -DCMAKE_CXX_COMPILER=clang-12, it will report errors like this:
Undefined symbols for architecture x86_64:
...
"std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main.cpp.o
...
According to my experience, the compiler (and linker) seems treat my project as a C project, not a C++ one.
So I’m curious what’s the different between -DCMAKE_CXX_COMPILER=clang++and -DCMAKE_CXX_COMPILER=clang-12? Why the former works well but the latter doesn’t, since they are the same (which is clang-12)?
What’s more, I’m using an IDE, which will “cleverly” change -DCMAKE_CXX_COMPILER=clang++ to -DCMAKE_CXX_COMPILER=clang-12. So in this case, what can I do in writing CMake code to make CMake treat my project as a C++? (I tried project(untitled2 CXX) but it doesn’t work).
P.S. I’m using macOs, not sure if this happens on linux.