Quick Tutorial on Configuring CLion on Windows
If you are using CLion on Windows, you need to provide CLion with a UNIX-compatible environment, including a compiler and additional sets of tools. CLion is compatible with two environments: Cygwin and MinGW. Alternatively, you can use Microsoft Visual C++ compiler. These environments are more or less equivalent for purposes of development. This guide covers the installation and configuration of both of these environments: which one to choose is up to you.
Before we begin, it’s worth noting that, when you start up CLion, it will attempt to actively detect your existing operating environment automatically. So, if you have MinGW or Cygwin installed already, CLion will do its best to locate those by itself. There might be cases where it will not succeed though — such as in the case of missing packages or unsupported versions.
Since Microsoft Visual C++ compiler is supported experimentally for now, you need to enable it manually. After that CLion detects it's version automatically.
Both the installation and upgrade of Cygwin happen from the executable you download on the Cygwin download page. After firing up the installation and choosing the install directly (e.g., c:\cygwin64 for 64-bit), you need to pick the packages to install. The packages that CLion needs are:
Alternatively, you can just install the gcc-g++ and gcc-core package. These two packages, make and GDB have all that CLion needs and more.
To install a package, simply search for it in the Select Packages window and click the name until a tick mark appears in the Bin? column:
Once you’ve installed Cygwin, open CLion’s settings in Build, Execution, Deployment | Toolchains. From the drop down list of available environments, choose Cygwin. Specify the path to Cygwin or select the preferred Cygwin installation from the list. CLion will validate your settings and, if everything is OK, will present the following:and navigate to
You can use MinGW instead of Cygwin as the operating environment that CLion can use. MinGW can be installed in many ways: you can install the official distribution, the mingw-w64 distribution or, alternatively, one of the pre-made distributions such as TDM-GCC. In this guide we will take a look at the default distribution only.
To install MinGW, go to the downloads page and download
mingw-get-setup.exe. This executable will help you install all the required packages that CLion needs to operate.
Fire up the installer and pick your path (e.g.,
c:\MinGW). Now MinGW will go off and download a database that lists all available packages that can be installed. You will then be presented with the Installation Manager window where you need to pick at least the packages shown below: Now, simply choose from the menu, press Apply in the dialog that opens and wait for the packages to download and install.
Once you have completed MinGW installation, you can go to the Toolchains settings dialog ( ) and set up MinGW as your working environment, as it is described above.
Microsoft Visual C++ compiler
In addition to MinGW or Cygwin as operating environments for CLion, you can try using Microsoft Visual C++ compiler. CLion supports that compiler with CMake and NMake generator. With Microsoft Visual C++ you are able to work with the various cross-platform projects which often use Microsoft Visual Studio under Windows as a working environment.
To begin with, you need either Visual Studio 2013, 2015 or 2017 to be installed on your system. Having that, configure CLion to use Visual C++ compiler:
- First of all, enable the Visual Studio support. To do that, go to the Registry. In the dialog that opens type msvc and select the highlighted option, as follows: main menu option (or press Ctrl+Shift+A) and type
- Now you need to set up Microsoft Visual C++ compiler as your environment. Go the the Toolchains settings dialog ( ) and select Visual Studio from the list of available environments. Note, that CLion automatically detects the Visual Studio version installed on your system.
- Specify there the architecture (x86, amd64, x86_arm, amd64_arm, etc), type of a platform (store or uwp or leave it blank) and version (Windows SDK name or leave it blank).
- That's all. Now you can build your project with MSVC and run it. Note, that CLion will run CMake with the NMake generator in this case.
CLion tries its best to indicate whether or not a particular part of the required infrastructure is configured. If you attempt to compile without a predefined toolset, you will get an error similar to the following: Similarly, if you neglect to install one of the constituent parts, the Toolchains option page will perform the requisite validation and will indicate which part is missing:
There are two essential tools that CLion needs. First is CMake, which is used as the project/build system: think of it as an alternative to other popular build systems such as MSBuild (used by Visual Studio) or Qmake. CMake is fundamentally different to, say, Visual Studio in that CMake is not really a build system: instead, it is a build generator that produces build scripts in different formats, Visual Studio included. As a consequence, CMake does not have the equivalent notion of a solution: instead, several different binaries can be built out of a single CMakeLists.txt file as different targets.
You can find out more about CMake in our Working with CMake guide.
CLion comes bundled with a compatible version of CMake. As an alternative, you can specify a path to your own CMake distribution. You can download a distribution of CMake here.
While CMake tries to be very generic, you can get it to perform actions specific to a particular operating system. For example, the following clause
if (WIN32) #do something endif (WIN32)
GDB, the GNU Debugger, is what CLion uses for debugging your C++ applications. It is an essential part that is required by CLion to function properly.
If you are using MinGW, CLion comes with bundled GDB. Please note, however, that the option to use it is only available for MinGW; for Cygwin, you will have to install the appropriate package in the Cygwin Package Manager, as described in the Cygwin section of this guide.
Running and Debugging a Program
In order to run a program, you first need to make sure that you have both a target that gets built as well as a configuration that gets executed. A configuration is essentially a specification of what gets executed and how. If you open an existing project, a configuration will be created for each target automatically (see this tutorial for further info on run/debug configurations). If you want to change an existing configuration or create a new one, you can do this by choosing in the menu. The configuration editor looks as follows:
For a configuration, you need to specify the CMake target, the configuration and the actual executable that you are going to run. There’s also scope for specifying additional parameters.
Once you are done, you can fire up a program either by choosing , pressing Shift+F10 or pressing the triangle button in the menu bar on the top right of the window:
Note that running the app does not start a debug session. To start debugging, choose , press Shift+F9 or press the bug icon in the above menu bar. When execution pauses, an additional debugging tool window opens:
This tool window lets you inspect the internal state of the variables in different threads, set watches, evaluate expressions and a lot more. The GDB tab shows the GDB console output.
Debugging a program works the same as in other IDEs: you set the breakpoints (click on the margin or press Ctrl+F8) and then, once the debug session is initiated, execution gets paused at the breakpoint.