Codectionary / Developer documentation / C++

Install CLion, select a C++ toolchain, create a CMake project and use its run, debugger and code-completion tools.

What CLion does

JetBrains CLion is a cross-platform integrated development environment (IDE) for C and C++ projects. It provides an editor, project navigation, code analysis, completion, run configurations and a debugger in one application. It runs on supported Windows, macOS and Linux systems. CLion is an editor and project environment, not the C++ language or a substitute for a working compiler toolchain.

This guide follows CLion’s CMake project path. CMake describes what to build and CLion helps configure it; your selected compiler still translates the C++ source. You can write a first single-file program without CLion or CMake, so use the simpler first-program guide if you have not built a C++ file yet.

Install and activate CLion

Check JetBrains’ current system requirements and download CLion from its official site. JetBrains Toolbox App is one supported way to install and update it; a standalone installer is another. On macOS, choose the download for your processor architecture. Launch CLion, choose an eligible licence in its activation flow, then continue to the toolchain check. Installing the IDE alone is not proof that a compiler is ready.

JetBrains currently offers a free non-commercial CLion licence for qualifying personal learning and other non-commercial work, complimentary education programmes for eligible students and teachers, a trial, and paid commercial subscriptions. The non-commercial option has its own terms and account activation; it is not a blanket free licence for paid work. Review JetBrains’ current eligibility and terms before choosing an option, especially if your project’s purpose changes.

Choose and verify a toolchain

Open Settings (Preferences on macOS), then Build, Execution, Deployment > Toolchains. Inspect the selected environment, build tool, C compiler, C++ compiler and debugger. CLion tries to detect available tools and reports missing components. Keep one coherent toolchain selected for this first project; do not combine an MSVC compiler with unrelated MinGW libraries or a different debugger without a reason.

On Windows, current CLion installations can use the bundled MinGW toolchain or an installed Visual Studio/MSVC toolchain. On macOS, Apple Clang from Xcode or Command Line Tools is a straightforward choice. On Linux, install GCC/G++ or Clang using your distribution’s packages first. The paths and detected compiler version should match what you installed; if detection fails, follow the relevant OS setup guide and select the correct toolchain rather than assuming CLion itself compiled anything.

Create a C++ executable project

From the Welcome screen, choose New Project, then C++ Executable. Choose a folder and a C++17 language standard for this example, and create the project. CLion normally generates a root CMakeLists.txt and a main.cpp source file. Open main.cpp and replace the generated program with the complete example below, keeping only one main function.

The CMakeLists.txt file describes the project and its executable target. CLion loads that description and creates a CMake profile with a build directory, often named cmake-build-debug for a Debug configuration. The source file remains in your project folder while object files and the executable go in the build directory. The exact generated CMake text and build-folder name may differ by IDE version or settings.

main.cpp: a complete first program

#include <iostream>

int main() {
  std::cout << "Hello, Codectionary!\n";
  return 0;
}

Build and run the selected target

Wait for CLion to finish loading the CMake project. Select the executable target in the run-configuration menu and use Build, then Run. The Run tool window should show Hello, Codectionary! and a successful process exit. Saving source alone does not replace a previously built binary; rerun through the IDE so it rebuilds as needed.

If CLion says it cannot find a compiler, build tool or debugger, revisit Toolchains. If CMake reports that it cannot configure the project, check the selected profile, the generated CMakeLists.txt and the first error in the CMake tool window. If a C++ diagnostic names a line in main.cpp, correct the code and build again. These failures occur at different stages.

Use breakpoints and inspect values

A debugger lets you pause a running program. Click the gutter beside the std::cout line to set a breakpoint, then choose Debug for the selected target. When execution stops, inspect the current source line and variables in the Debug tool window; step over a line to watch execution move forward, then resume. For this tiny program there are few values to inspect, so try adding a named integer before the output statement and printing it.

A breakpoint is useful only when the program reaches that line and a suitable debugger is configured. If debugging cannot start, check the debugger entry in Toolchains and use a Debug CMake profile. An optimized Release build may make stepping and variable inspection less predictable.

Use completion without trusting it blindly

CLion offers context-aware completion for visible names, types and keywords. Start typing std::cou in the source file and invoke basic completion from the Code menu if suggestions do not appear automatically. Selecting a suggestion can save typing, but compilation remains the check that the chosen symbol and its required header are valid. When completion is incomplete, verify that CMake loaded successfully and the file belongs to the project.

Once the single-file project works, add a second .cpp file and a header. That is when CMake’s source list and include paths begin to earn their keep. The project-structure and CMake guides show the pieces separately so the IDE does not hide the underlying build model.

Syntax

#include <iostream>

int main() {
  std::cout << "Hello, Codectionary!\n";
  return 0;
}

Examples

Run a complete program from a CLion CMake project

Replace the generated main.cpp, keep one main function, then choose the executable target and Run.

#include <iostream>

int main() {
  std::cout << "Hello, Codectionary!\n";
  return 0;
}
  1. The goal is to verify the IDE, selected compiler and CMake project can build and run together.
  2. #include <iostream> makes std::cout available. main contains the output statement and returns success.
  3. The string includes a newline escape, so the Run window shows Hello, Codectionary! on one line.
  4. If CLion cannot build, inspect the first toolchain, CMake or compiler diagnostic; those messages identify different setup problems.

Best practices

  • Check toolchain detection before blaming C++ source for a missing compiler.
  • Use a Debug profile and a configured debugger when learning to step through code.
  • Review the current JetBrains licence terms for the purpose of your work.

Runtime & versions

Compiled native applications. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

ISO C++ resources

Specifications & further reading