How to switch between GCC and Clang in Clion from CMakeLists.txt using windows / cygwin

I put

set(CMAKE_CXX_COMPILER "/usr/bin/clang.exe") 

Run / clean, run / compile.

I get link errors, for example:

 undefined reference to `std::ios_base::Init::~Init()' : undefined reference to `__gxx_personality_v0' 

Presumably there are other variables. I tried adding -lstdc++ to CMAKE_CXX_FLAGS , but no different.

Is there a CLion method, as opposed to a CMake method, for example?

Thanks.

+6
source share
1 answer

Setting the compiler with CMake is a bit delicate. Although the method you use setting CMAKE_CXX_COMPILER in CMakeLists.txt works, this is the least recommended way in CMake Help .

CLion supports CMake's FAQ method 2: using -D in a cmake call. Setting variables in CMakeLists.txt is not affected.

On a Mac, go to Preferences

On Linux / Windows, go to File | Settings File | Settings

then Build, Execution, Deployment | CMake | CMake options Build, Execution, Deployment | CMake | CMake options Build, Execution, Deployment | CMake | CMake options and enter the text:

 -D CMAKE_C_COMPILER=/path/to/c_compiler -D CMAKE_CXX_COMPILER=/path/to/c++_compiler 

See the CLion FAQ for more details.

Also note that when changing compilers, you will have to invalidate the CLion cache and restart, see my answer to How to clear the CMake cache in Clion? .

EDIT

After I wrote this answer, CLion added support for several build directories, as noted in @rubenvb's comments. This is another way to explore.

+11
source

Source: https://habr.com/ru/post/987756/


All Articles