CLion 2016.1 Help

Quick Tutorial on Configuring CLion on Windows

Contents:

Basics

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. 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.

Cygwin

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:

  • GCC- G++
  • make

Alternatively, you can just install the GCC- G++ and GCC- core package. The two packages 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:

cl_CygwinSetup

Once you’ve installed Cygwin, open CLion’s settings in File | Settings and navigate to Build, Execution, Deployment | Toolchains. Select Use Cygwin home and specify the path to Cygwin. CLion will validate your settings and, if everything is OK, will present the following:

cl_WinTutorialTools

MinGW

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:

cl_MinGWInstall
Now, simply choose Installation | Apply Changes from the menu, press Apply in the dialog that opens and wait for the packages to download and install.

Special Note on MinGW-W64

If you are planning to install the MinGW-W64 distribution package, you should be aware of the following issue, which some of our users have encountered. During set-up, the installer offers us an option to specify the version of the installation:

cl_setupMinGW

This version parameter represents, in fact, the version of the GCC compiler – not the version of the MinGW distribution. CLion adds additional information to the settings window to prevent possible confusion, as can be seen below:

cl_WinTutorialVersions

Diagnosing Problems

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:

cl_WinTutorialDiagnistics
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:
cl_WinTutorialEnv1
And while compilation in this situation may succeed, CLion will, of course, refuse to initiate a debug session:
cl_WinTutorialError
In addition to GDB, some of the possibly missing parts might include either make or G++, in which case you’ll see something like the following:
cl_WinTutorialEnv2

CMake

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)
will only be invoked in a Win32 setting.

GDB

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 Run | Edit Configurations… in the menu. The configuration editor looks as follows:

cl_WInTutorialRun

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 Run | Run , pressing Shift+F10 or pressing the triangle button in the menu bar on the top right of the window:

cl_WinTutorialTriangle

Note that running the app does not start a debug session. To start debugging, choose Run | Debug , press Shift+F9 or press the bug icon in the above menu bar. When execution pauses, an additional debugging tool window opens:

cl_WInTutorialFrames

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.

See Also

Last modified: 20 July 2016