Skip to content

CLion

Introduction

CLion is a feature-rich and powerful cross-platform C/C++ Integrated Development Environment (IDE) developed by JetBrains.

Clion

Official Tutorials

The official website provides tutorials for Learning CLion.

Installation

Refer to Download CLion.

Configuration

Toolchain Installation

CLion does not come with a compiler, build tools, or debugger by default; they need to be installed manually.

Windows

Refer to Tutorial: Configure CLion on Windows | CLion Documentation

It's worth mentioning that the Windows version of CLion comes with MinGW bundled, so you may not need to install the MinGW toolchain separately.

Linux

Debian/Ubuntu and Derivatives

1
2
3
sudo apt install make cmake # build tools
sudo apt install gcc g++ gdb # compiler and debugger
sudo apt install clang clang++ llvm lldb # you can also choose to use clang toolchain

Arch Linux and Derivatives

1
2
3
sudo pacman -S make cmake # build tools
sudo pacman -S gcc g++ gdb # compiler and debugger
sudo pacman -S clang clang++ llvm lldb # you can also choose to use clang toolchain

Fedora/RHEL/CentOS/Rocky Linux

1
2
3
sudo dnf install make cmake # build tools
sudo dnf install gcc g++ gdb # compiler and debugger
sudo dnf install clang clang++ llvm lldb # you can also choose to use clang toolchain

macOS

Refer to Tutorial: Configure CLion on macOS | CLion Documentation

Toolchain Settings

Manual Toolchain Setup

A newly installed CLion will automatically detect the C/C++ development toolchain in your system. If an installed toolchain cannot be auto-detected, you can manually configure it in Settings under Build, Execution, Deployment > Toolchains.

Config Toolchains

Compiling, Running, and Debugging

Although CLion was originally designed for complex multi-file C/C++ projects, and earlier versions defaulted to using CMake as the build tool, starting from CLion 2022.3, CLion now supports Running Single C, C++ Files.

There are multiple ways to run a C++ program. A simple workflow is as follows:

  1. Create a C/C++ project: New -> Project -> C++ Executable, choose an appropriate location and language standard version, then click Create.
  2. Open the project. The project directory should now contain a cmake-build-debug folder, a CMakeLists.txt file, and a main.cpp file. Since we don't need CMake to manage the project, we can delete the CMakeLists.txt file and the cmake-build-debug directory along with all its contents.
  3. Open the main.cpp file, right-click in the editor area, and you will see the Run 'main.cpp' option. Selecting this option will allow CLion to automatically create a run configuration and execute the program.

C++ Single File Execution

To debug the program, set breakpoints in the editor, right-click in the editor area, and select the Debug 'main.cpp' option.

Compiling, Running, and Debugging via CMake

Settings

CLion can also use CMake as the build tool. CMake settings can be modified under Build, Execution, Deployment -> Toolchains -> CMake.

CMake Settings

Compilation Options

CMake uses the CMakeLists.txt file in the project root directory as the configuration file for building the project by default. You can use the add_compile_options command to add compilation options, for example:

1
add_compile_options(-std=c++17 -DDEBUG)

For other CMake features, please refer to the CMake Official Documentation

Obtaining a Free CLion IDE License

CLion is a paid product, but you can apply for special licenses through an educational email or an open-source project. After approval, you can not only use the official CLion IDE for free but also other paid products developed by JetBrains.

Using an Educational Email

Go to the official Free Educational Licenses page, click the Apply button, and fill in the relevant information to apply.

Educational Licenses

Note: When registering, please use an educational email with an @edu.cn suffix for the email option. The special license requires email verification before it can be obtained.

You can apply for an educational email through your university's academic affairs center website. If you cannot apply for one, you may need to use 学信网 for verification (Mainland China only).

Using an Open-Source Project

If you are a core developer or maintainer of an open-source project, you can try applying for an Open Source Development License. The application process is similar to the educational license but requires filling in the repository address of the open-source project.

Open Source Development License