Clang and Clang++ mutually exclusive

When I change the CMAKE_C_COMPILER to clang Clion automatically changes  the CMAKE_CXX_COMPILER to g++ and when I change the CMAKE_CXX_COMPILER  to clang++ it changes the CMAKE_C_COMPILER to gcc. This is under  Windows. Is there a specific reason for this and is there a workaround?

Comment actions Permalink

Hi Mitchell.

Could you please try to use method #2 from pass
-D CMAKE_C_COMPILER=<your_path_to_c_compiler>  -D CMAKE_CXX_COMPILER=<your_path_to_cxx_compiler>
to Preferences (Settings) | Build, Execution, Deployment | CMake | CMake options.

Then corresponding CMake cache variables will be overwritten respectively.

Will it work better?
Comment actions Permalink

Thanks for the response. That's half right. Clion will autoregenerate the CMake cache/settings to use gcc or g++ (depending on its whim) if you do that. From what I can tell, the reason is that Clion can't change compiler once the build tree has been created. Unfortunately, it creates the build tree before you have the chance to change compilers. The solution (for me) is to change the flags with -D as you said, close Clion, then delete the generated files (under C:\Users\<username>\.clion\system\cmake\generated\) then reopen Clion. From there it should recreate the build tree and also automatically set the flags correctly under the cache settings. So after that you can remove the -D flags, not that it's important at that point.


Please sign in to leave a comment.