How can I change compilers in CLion?

Since CLion relies on CMake build system. To change the compiler used in CLion, use method #2 from the official CMake documentation.

Go to Preferences/Settings | Build, Execution, Deployment | CMake | CMake options and pass the following commands:

-D CMAKE_C_COMPILER=<your_path_to_c_compiler>
-D CMAKE_CXX_COMPILER=<your_path_to_cxx_compiler>

The corresponding CMake cache variables will be overwritten.

Also find more details and samples in our Quick CMake Tutorial.

 

4 comments

Is there a way to set this as a default setting? So far, I have to set the compiler for every project I create.

Thanks

0

Setting the compiler to an invalid value (in this case "ccache cc") broke everything astonishingly, impressively, and most comprehensively: removing the change, reloading the CMake project, re-creating the entire project, and in fact deleting all the CLion preferences and reinstalling CLion did not fix it.  Clearly there's something I've missed, but it's definitely serious business changing this setting, and it doesn't take well to mistakes.

Edited by Cja987
0

You can set ccache through CMakeLists.txt

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
    SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
    SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
0

Please sign in to leave a comment.

Have more questions?

Submit a request