How can I change compilers in CLion?

Starting with CLion 2017.3, go to Settings/Preferences | Build, Execution, Deployment | Toolchains , select the toolchain you'd like to configure (you can use several at a time), change C/C++ compilers path there.

As an alternative or for older CLion versions:

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.

 

26 out of 31 found this helpful
5 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

This is most likely will come together with this request: https://youtrack.jetbrains.com/issue/CPP-1887

1

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)
1

I am getting a problem with this approach when trying to set the STM32CubeIDE as the compiler. While loading the CMake project, it will try to execute a compile of some test program, but there is an assumption that "-rdynamic" must work. But the STM32 provided cross-compiler spits out an error, and loading the project fails;

    /opt/st/stm32cubeide_1.12.0/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.linux64_1.0.200.202301161003/tools/bin/arm-none-eabi-gcc -rdynamic CMakeFiles/cmTC_84571.dir/testCCompiler.c.obj -o cmTC_84571 
    arm-none-eabi-gcc: error: unrecognized command-line option '-rdynamic'

I am trying to get CLion to compile and debug https://github.com/Lora-net/LoRaMac-node which can be compiled from command line as;

rm -rf build 2>/dev/null
mkdir build
cd build && cmake -DCMAKE_BUILD_TYPE=Release \
-DTOOLCHAIN_PREFIX="/opt/st/stm32cubeide_1.12.0/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.linux64_1.0.200.202301161003/tools" \
-DCMAKE_TOOLCHAIN_FILE="../cmake/toolchain-arm-none-eabi.cmake" \
-DAPPLICATION="ping-pong" \
-DCLASSB_ENABLED="ON" \
-DREGION_EU868="ON" \
-DBOARD="NucleoL073" \
-DMBED_RADIO_SHIELD="SX1276MB1LAS" \
-DUSE_RADIO_DEBUG="ON" ..
make

And the STM32CubeIDE is installed in /opt/st

0

Please sign in to leave a comment.

Have more questions?

Submit a request