CLion 2021.3 Help

Toolchains

For CMake, Makefile, and compilation database projects in CLion, a toolchain is a set of all the necessary tools required for building and running your application: the CMake executable (CMake projects), the make tool, the C/C++ compilers, the debugger binary, and the working environment.

When you start working with CLion, you already have a default toolchain available. Although you can use it in development, you may also want to adjust the set of tools for the needs of your project (for example, switch to another compiler).

Select the kind of project you are working with to learn more:

CMake projects

CLion uses the configured toolchain to build and run your CMake application. After you set up a toolchain, you can select it in CMake profile settings.

Makefile projects

CLion uses the selected toolchain when loading Makefile projects. The toolchain also provides the debugger for Makefile Application configurations.

After configuring a toolchain, you will be able to select it in Settings / Preferences | Build, Execution, Deployment | Makefile.

See Makefiles: Adjust project settings.

Compilation database projects

CLion uses the selected toolchain for resolving the compilation database project files.

After configuring a toolchain, you will be able to select it in Settings / Preferences | Build, Execution, Deployment | Compilation Database. Note that Remote toolchains are not supported for compilation database projects.

See Compilation database: Check the toolchain.

Custom build targets and applications

The selected toolchain provides the environment and the debugger for custom run/debug configurations. See Creating a custom build target.

Create a toolchain

  1. Go to Settings / Preferences | Build, Execution, Deployment | Toolchains and click Icons general add to add a new toolchain.

    Watch this video for an overview of Windows toolchain options:

    Select one of the pre-defined toolchain setups (MinGW, Cygwin, Visual Studio, or WSL), Remote Host, Docker) or configure a custom toolchain (System):

    Windows toolchain options

    On Linux or macOS, choose the type of your toolchain: System for local projects, Remote Host or Docker for remote development.

    macOS toolchains
  2. To initialize the toolchain environment via a script, click Add environment and specify the path to the file. See below for more information.

  3. If required, switch from the bundled CMake to a custom CMake installation of your choice.

  4. CLion will attempt to detect the make utility and the C/C++ compilers.

    If you prefer to use custom make and compilers instead of the detected ones, provide the paths in Make, C Compiler, and C++ Compiler. See Switching compilers.

  5. Select the Debugger.

    You can switch between the bundled GDB (currently v 10.2 for macOS, v 10.2 for Windows and Linux) and LLDB (version 13.0.0 on macOS or Linux and 9.0.0 on Windows MSVC), or choose a custom GDB.

    Note that custom LLDB is not currently supported.

  6. CLion verifies your choices and notifies you if any of the tools or packages are missing.

  7. When the configuration is completed, click OK to save it.

Initializing the toolchain environment via a script

You can point CLion to the script that initializes the environment for your project without the need to set the variables manually. 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. However, it is not supported for CMake presets at the moment (CPP-26576).

Environment sourcing will happen on the first actual usage of the toolchain in a CMake profile or upon loading a Makefile project.

  1. In the toolchain settings, click Add environment, then click From file:

    Setting a script to initialize the environment
  2. In the Environment file field, specify the path to the script:

    Environment initialization via a script
  3. 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.

    Environment script loading report
Last modified: 19 January 2022