In CLion, you can use GCC-based compilers, Clang, Clang-cl, Visual Studio C++ compiler, as well as IAR compiler and custom-defined compiler.
The compilers you configure in the currently selected toolchain are used for all the projects you work with in CLion.
Change toolchain compilers
-
Go to and select the toolchain you want to edit.
-
In the C++ Compiler or C Compiler fields specify the path to the desired installation, for example:
Project compilers
If you need to use non-default compilers, you can change the paths in toolchain settings (IDE-wide) or set the compilers manually, affecting the current project only.
Compilers for Cmake projects
For CMake projects, you can change the compilers in the CMake profile settings defined per project.
Change CMake profile compilers
-
Go to .
-
In the CMake options field, specify the compiler by setting the CMAKE_LANG_COMPILER variable:
-D CMAKE_<LANG>_COMPILER=[fully qualified compiler name]
The
LANG
part specifies the language (C for C and CXX for C++), and you need to provide the full path to the compiler, for example: -
After you apply the settings, CLion will reset the CMake cache and reload your project.
Last modified: 11 January 2023
On Windows, CLion toolchains include the build tool, C and C++ compilers, debugger executable, and the environment. You can select one of the pre-defined toolchain setups (MinGW, Cygwin, Microsoft Visual C++, or WSL), Remote Host, Docker) or configure a custom toolchain (System):
Watch this video for an overview of Windows toolchain options:
For details on Remote Host toolchains, see Remote with local sources. If you are working with a Docker container, see Docker toolchain.
MinGW
CLion bundles a version of the MinGW toolset for quick setup. The exact version bundled is MinGW-w64 9.0 with languages=c,c++
, posix
threads, and seh
exceptions. You can use this bundled toolchain or switch to a custom MinGW installation.
Install MinGW (optional)
-
Download and run the MinGW-w64 installer. It provides both 64- and 32-bit options.
-
In the MinGW-w64 installation wizard, make sure to select the required architecture. Note that the default suggested option is 32-bit.
-
Wait for installation to finish.
Although MinGW-w64 provides both 64- and 32-bit options, you can also install MinGW, the 32-bit-only version.
-
In the MinGW installation wizard, select the following packages from the Basic Setup list: mingw-developer-tool, mingw32-base, mingw32-gcc-g++, mingw32-msys-base.
-
Wait for installation to finish.
Configure a MinGW toolchain
-
Go to .
Click and select MinGW to add a new MinGW toolchain.
-
In the Toolset field, you will see Bundled MinGW, which is the default option. If required, open the field to select from the list of other available installations:
-
Wait until the tools detection finishes.
-
Select the Debugger: you can use either bundled GDB, your MinGW GDB, or a custom GDB binary.
The recommended option is bundled GDB, since it is guaranteed to include Python support required for CLion data renderers.
-
If required, specify the script to initialize the environment.
-
Click Apply when all the tools are set correctly.
Cygwin
-
Download the Cygwin installer, version 2.8 or later.
-
Run the installer and select the following packages:
-
gcc-g++
-
gdb
To select a package, type its name in the Search field and set the version in the New column:
-
-
Once the installation is finished, open CLion and go to .
-
Click and select Cygwin to add a new Cygwin toolchain.
CLion will attempt to detect the Cygwin installation automatically. Check the Toolset field, and specify the path manually if required.
-
Wait until the tools detection finishes, and click Apply.
-
If required, specify the script to initialize the environment.
Windows Subsystem for Linux
You can use WSL, Windows Subsystem for Linux, as your working environment in CLion on Windows 10 (starting the Fall Creators Update version 1709, build 16299.15).
WSL toolchain enables you to build projects using CMake and compilers from Linux and run/debug on WSL without leavCLionLion running on your Windows machine.
Microsoft Visual C++
-
Install Visual Studio 2013, 2015, 2017, 2019, or 2022 on your system.
-
In CLion, go to .
-
Click and select Visual Studio from the list of toolchain templates.
-
Check the Toolset field. CLion will attempt to automatically detect the installed Visual Studio distribution. If the detection fails, set the path to Visual Studio manually.
-
If required, specify the Architecture (x86, amd64, x86_arm, or another), Platform (store, uwp, onecore, or leave it blank), and Version. To build your project for the selected architecture, CLion will call the script to configure the environment with the specified parameters.
-
Wait until the tools detection is finished:
-
If required, specify the script to initialize the environment.
MSVC compiler
CLion supports the Microsoft Visual C++ compiler that ships with Visual Studio 2013, 2015, 2017, 2019, and 2022.
For the case when your code includes MSVC extensions, CLion provides the support for:
-
__uuidof
,__forceinline
,__unaligned
, and__alignof
keywords; -
pointer type attributes:
__ptr32
,__ptr64
,__uptr
,__sptr
; -
MSVC built-in data types:
(unsigned) __int8
,(unsigned) __int16
,(unsigned) __int32
,(unsigned) __int64
,__wchar_t
; -
additional format specifiers, such as
%I32
and%I64
; -
the clang’s
-fms-extensions
flag.
Clang-cl compiler
As an alternative compiler, you can use clang-cl — the MSVC-compatible compiler driver for Clang. CLion supports clang-cl version 8.0 and later.
-
Install clang-cl from the LLVM site or along with the Visual Studio tools.
When installed from the LLVM site, the clang-cl binary can be found at the standard location C:Program FilesLLVMbinclang-cl.exe for the 64-bit version or C:Program Files (x86)LLVMbinclang-cl.exe for the 32-bit version.
-
In CLion, go to and select the Visual Studio toolchain that you want to configure, or create a new one.
-
Point the C Compiler and C++ Compiler fields to clang-cl.exe. CLion will suggest the paths detected automatically.
Note that currently the -T clangcl
options can’t be picked up if the bundled CMake is in use along with the Visual Studio toolchain setup (CPP-18848).
MSVC debugger
The MSVC toolchain debugger is implemented on top of LLDB, and it can work with native visualizers from the Visual Studio installation or from your project.
To enable native visualizers support and set the desired diagnostics level, select the Enable NatVis renderers for LLDB checkbox in :
CLion automatically generates one-line summaries for all structures not covered by Natvis and highlights them to increase readability. Also, the built-in formatters provide visualization for wide/Unicode strings (wchar_t
, char16_t
, char32_t
).
If you have custom native visualizers in your project, CLion will use them as well.
CLion supports most of the Natvis customization features, such as ArrayItems, IndexListItems, LinkedListItems, TreeItems, Inheritable attribute, Format specifiers, and CustomListItems.
When using the MSVC toolchain debugger, you can enable symbol servers support which will help the debugger resolve library symbols correctly. For more details, refer to Using symbol servers when debugging on Windows.
System toolchain
The System toolchain on Windows allows configuring the build tool, compilers, and debugger without selecting a predefined toolset or environment, similarly to Linux and macOS. Use this toolchain option for embedded development cases like using ARM or for other custom setups.
-
Go to .
-
Click and select System to add a new System toolchain.
-
Configure the tools and provide an environment script if required:
Initializing the toolchain environment via a script
Instead of setting the environment manually, you can point CLion to an environment file — a script that initializes the environment for your project. This is helpful, for example, when you need to initialize compiler variables, add custom ones, or modify the PATH
.
Specifying an environment script is available for all toolchains.
Environment sourcing will happen on the first actual usage of the toolchain in a CMake profile or upon loading a Makefile project.
-
In the toolchain settings, click Add environment, then click From file:
-
In the Environment file field, specify the path to the script:
-
You will get notifications in case of script loading issues. CLion also checks the script loading time and terminates the execution if it takes too long.
Clang compiler on Windows
With CMake 3.15, it has become possible to use the Clang compiler on Windows with the MinGW-w64/MinGW toolchain.
However, the LLVM Clang for Windows is built using Microsoft Visual Studio, and all the built-in macros and include search paths are set up for use with Visual Studio. So if you take Clang from the LLVM repository, it will not work correctly when configured with the MinGW toolchain. One of the possible workarounds is described below.
Set up the Clang compiler for MinGW
-
Install MSYS2.
-
Download the following packages with the pacman tool (use the
pacman -S package_name
command):-
mingw-w64-x86_64-gcc
-
mingw-w64-x86_64-clang
-
mingw-w64-x86_64-lld
-
mingw-w64-x86_64-gdb
-
mingw-w64-x86_64-polly
-
mingw-w64-x86_64-compiler-rt
This way, you will get the Clang compiler which is built with mingw-w64 and has paths and macros that correspond to this toolchain.
-
-
Go to , create a MinGW toolchain, and set up the tools from MSYS.
After specifying the Toolset, check the automatically detected tools and make sure to switch to Clang in the C Compiler and C++ Compiler fields.
GDB on Windows
In the case of MinGW, CLion includes the bundled GDB (version 12.1). For Cygwin, you need to install the GDB package in the Cygwin Package Manager, as described in the Cygwin section of this guide.
You can also switch to a custom GDB binary. In this case, the supported GDB versions are 7.8.x-12.1.
Note that for GDB 8.0 and later, debugger output is redirected to CLion console by default. To enable opening an external console window for application input/output, go to Help | Find Action or press Ctrl+Shift+A, search for Registry, and set the following key: cidr.debugger.gdb.workaround.windows.forceExternalConsole.
Last modified: 11 January 2023
I ran into the same issue with CLion 1.2.1 (at the time of writing this answer) after updating Windows 10. It was working fine before I had updated my OS. My OS is installed in C: drive and CLion 1.2.1 and Cygwin (64-bit) are installed in D: drive.
The issue seems to be with CMake. I am using Cygwin. Below is the short answer with steps I used to fix the issue.
SHORT ANSWER (should be similar for MinGW too but I haven’t tried it):
- Install Cygwin with GCC, G++, GDB and CMake (the required versions)
- Add full path to Cygwin ‘bin’ directory to Windows Environment variables
- Restart CLion and check ‘Settings’ -> ‘Build, Execution, Deployment’ to make sure CLion has picked up the right versions of Cygwin, make and gdb
- Check the project configuration (‘Run’ -> ‘Edit configuration’) to make sure your project name appears there and you can select options in ‘Target’, ‘Configuration’ and ‘Executable’ fields.
- Build and then Run
- Enjoy
LONG ANSWER:
Below are the detailed steps that solved this issue for me:
-
Uninstall/delete the previous version of Cygwin (MinGW in your case)
-
Make sure that CLion is up-to-date
-
Run Cygwin setup (x64 for my 64-bit OS)
-
Install at least the following packages for Cygwin:
gcc
g++
make
Cmake
gdb
Make sure you are installing the correct versions of the above packages that CLion requires. You can find the required version numbers at CLion’s Quick Start section (I cannot post more than 2 links until I have more reputation points). -
Next, you need to add Cygwin (or MinGW) to your Windows Environment Variable called ‘Path’. You can Google how to find environment variables for your version of Windows
[On Win 10, right-click on ‘This PC’ and select Properties -> Advanced system settings -> Environment variables… -> under ‘System Variables’ -> find ‘Path’ -> click ‘Edit’]
-
Add the ‘bin’ folder to the Path variable. For Cygwin, I added:
D:cygwin64bin
-
Start CLion and go to ‘Settings’ either from the ‘Welcome Screen’ or from File -> Settings
-
Select ‘Build, Execution, Deployment’ and then click on ‘Toolchains’
-
Your ‘Environment’ should show the correct path to your Cygwin installation directory (or MinGW)
-
For ‘CMake executable’, select ‘Use bundled CMake x.x.x’ (3.3.2 in my case at the time of writing this answer)
-
‘Debugger’ shown to me says ‘Cygwin GDB GNU gdb (GDB) 7.8’ [too many gdb’s in that line ;-)]
-
Below that it should show a checkmark for all the categories and should also show the correct path to ‘make’, ‘C compiler’ and ‘C++ compiler’
See screenshot:
Check all paths to the compiler, make and gdb
- Now go to ‘Run’ -> ‘Edit configuration’. You should see your project name in the left-side panel and the configurations on the right side
See screenshot:
Check the configuration to run the project
-
There should be no errors in the console window. You will see that the ‘Run’ -> ‘Build’ option is now active
-
Build your project and then run the project. You should see the output in the terminal window
I ran into the same issue with CLion 1.2.1 (at the time of writing this answer) after updating Windows 10. It was working fine before I had updated my OS. My OS is installed in C: drive and CLion 1.2.1 and Cygwin (64-bit) are installed in D: drive.
The issue seems to be with CMake. I am using Cygwin. Below is the short answer with steps I used to fix the issue.
SHORT ANSWER (should be similar for MinGW too but I haven’t tried it):
- Install Cygwin with GCC, G++, GDB and CMake (the required versions)
- Add full path to Cygwin ‘bin’ directory to Windows Environment variables
- Restart CLion and check ‘Settings’ -> ‘Build, Execution, Deployment’ to make sure CLion has picked up the right versions of Cygwin, make and gdb
- Check the project configuration (‘Run’ -> ‘Edit configuration’) to make sure your project name appears there and you can select options in ‘Target’, ‘Configuration’ and ‘Executable’ fields.
- Build and then Run
- Enjoy
LONG ANSWER:
Below are the detailed steps that solved this issue for me:
-
Uninstall/delete the previous version of Cygwin (MinGW in your case)
-
Make sure that CLion is up-to-date
-
Run Cygwin setup (x64 for my 64-bit OS)
-
Install at least the following packages for Cygwin:
gcc
g++
make
Cmake
gdb
Make sure you are installing the correct versions of the above packages that CLion requires. You can find the required version numbers at CLion’s Quick Start section (I cannot post more than 2 links until I have more reputation points). -
Next, you need to add Cygwin (or MinGW) to your Windows Environment Variable called ‘Path’. You can Google how to find environment variables for your version of Windows
[On Win 10, right-click on ‘This PC’ and select Properties -> Advanced system settings -> Environment variables… -> under ‘System Variables’ -> find ‘Path’ -> click ‘Edit’]
-
Add the ‘bin’ folder to the Path variable. For Cygwin, I added:
D:cygwin64bin
-
Start CLion and go to ‘Settings’ either from the ‘Welcome Screen’ or from File -> Settings
-
Select ‘Build, Execution, Deployment’ and then click on ‘Toolchains’
-
Your ‘Environment’ should show the correct path to your Cygwin installation directory (or MinGW)
-
For ‘CMake executable’, select ‘Use bundled CMake x.x.x’ (3.3.2 in my case at the time of writing this answer)
-
‘Debugger’ shown to me says ‘Cygwin GDB GNU gdb (GDB) 7.8’ [too many gdb’s in that line ;-)]
-
Below that it should show a checkmark for all the categories and should also show the correct path to ‘make’, ‘C compiler’ and ‘C++ compiler’
See screenshot:
Check all paths to the compiler, make and gdb
- Now go to ‘Run’ -> ‘Edit configuration’. You should see your project name in the left-side panel and the configurations on the right side
See screenshot:
Check the configuration to run the project
-
There should be no errors in the console window. You will see that the ‘Run’ -> ‘Build’ option is now active
-
Build your project and then run the project. You should see the output in the terminal window
Я хочу проверить Clang с CLion в Ubuntu. По умолчанию Clion обнаруживает мою установку gcc, но я хочу использовать clang вместо gcc. Более того, я не хочу устанавливать clang через apt-get. Я загрузил бинарный файл llvm, clang (3.6.2) с веб-сайта llvm. Я хочу использовать этот портативный двоичный файл.
Вот мои настройки системы:
- Убунту — 14.04
- gcc — 4.8.4
- llvm clang — 3.6.2 (переносной)
- CLion — 1.0.4
Итак, как настроить CLion с llvm-clang здесь?
4
Решение
Часто задаваемые вопросы заявляет следующее:
В настоящее время CLion поддерживает компиляторы GCC и Clang и руководствуется этими двумя способами, чтобы получить пути к библиотекам и заголовкам. В следующих выпусках мы планируем расширить список компиляторов, доступных в CLion.
Чтобы изменить компилятор, перейдите на вкладку «Кэш» в окне инструмента CMake и установите путь компилятора к переменной CMAKE_CXX_COMPILER. Затем нажмите Enter и нажмите кнопку «Применить изменения и перезагрузить»
3
Другие решения
Я получил ответ из блога CLion, и он работает, и вот оно.
Чтобы указать пути к компилятору CMake, перейдите в Настройки | Сборка, выполнение, развертывание | CMake и передать как параметры CMake:
-D CMAKE_C_COMPILER=
-D CMAKE_CXX_COMPILER=
В случае, если CMake не может найти какой-либо путь к библиотекам Clang и т. Д., Вы также можете установить там переменные окружения:
CC=/usr/bin/clang
CXX=/usr/bin/clang++
3
Единственный компилятор, который работает на моем CLion, — это clang, который по умолчанию обнаруживается в наборах инструментов. Мне нужно использовать gcc (мой класс в колледже использует компилятор gcc, поэтому я хочу избежать любых непредвиденных проблем) и установить его через homebrew. В моем терминале я могу выполнять команды g++ и gcc, и он использует правильный компилятор, но я не знаю, как это изменить в CLion. Должно быть, я делаю что-то не так с его расположением или настройками CMake. Любое руководство будет оценено и спасибо. Дайте мне знать, если есть какие-либо дополнительные вопросы, на которые я могу ответить, мое объяснение может быть недостаточным, так как я новичок в мире CS. Я вижу предыдущие вопросы о том, как переключать компиляторы между gcc и clang, но не конкретно на CLion.
2 ответа
Перейдите в файл> настройка> сборка, выполнение> цепочки инструментов и щелкните значок плюса, чтобы выбрать нужный компилятор. clion автоматически обнаружит Environment, cmake и все такое. нажмите «подать заявку».
см изображение
0
suraj pisal
4 Авг 2021 в 05:17