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?
请先登录再写评论。
Hi Mitchell.
-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?
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.