Configure Clang in CLion
Prologue
Alas, here it comes. CLion, enemy of Visual Studio… But, I had to admit, it is not that bad at all. ☹️
For some reason, I have to use Clang instead of commonly seen GCC. So, how to configure this in CLion. I used to believe that install Clang is as easy as install MinGW, but I was wrong. 😞 It takes some efforts. So… This is why you see this post.
1. Install Clang
Though you can install Clang tool chain in Visual Studio, but it can only work in Visual Studio, not in CLion. (Perhaps there is a way that I failed to discover?)
There is a relatively simpler way of downloading Clang without Visual Studio, that is via MSYS2.
1.1 Install MSYS2
Just go to MSYS2 official site to download the installer. One-click install, really easy.
During the installation, you can change where MSYS2 will be installed.
After installation, you will get a bunch of stuffs in the directory. But notice that, directories like mingw64\
, clang64\
are still empty, because we haven’t install any tools yet.
To make it clear, you’ve installed these 6 MSYS2s. 😧
1.2 Install Clang
For Windows users, we need MinGW Clang, and you can find its information on MSYS2 official package site. You can find the install command in this page.
- Package: mingw-w64-x86_64-clang
To save your time, the installation command is this. Paste it in any of the MSYS2 you’ve installed and execute.
1 | pacman -S mingw-w64-x86_64-clang |
You’ll then find the toolchain installed in mingw64\
directory.
2. Configure CLion
2.1 Add New Toolchain
Open CLion, go to Settings/Preferences | Build, Execution, Deployment | Toolchains, click add and select MinGW.
Then, Set paths to your MSYS2 installation directory. You only need to set Toolset and Compilers.
After all these, click Apply.
2.2 Set Toolchains of Project
One step away, you now can select the suitable toolchains for your project. Open Settings/Preferences | Build, Execution, Deployment | CMake, select a profile, and change the Toolchain it uses. Here, is MinGW-Clang.
Finally, click Apply and you are all set.
Epilogue
Well, I hate it to change my IDE to CLion, but… not bad, since I already use ReSharper in Visual Studio. Hmm… This is it, I guess. 😐