CLion 2023.1 Help

Quick start guide

0. Before you start

Is CLion a cross-platform IDE?

Yes, you can install and run CLion on Windows, macOS, and Linux.

  • See Install CLion for OS-specific instructions.

  • See CLion keyboard shortcuts for instructions on how to choose the right keymap for your operating system, and learn the most useful shortcuts.

What compilers and debuggers can I work with?

In CLion, you can use GCC-based compilers, Clang, Clang-cl, Visual Studio C++ compiler, as well as IAR compiler and custom-defined compiler. See Compilers for more information.

CLion supports debugging with GDB (either bundled or custom) on all platforms and with the bundled LLDB on macOS and Linux. Also, there is an LLDB-based debugger for the MSVC toolchain on Windows. Refer to the section on debugging below and to the page on Debugger options for details.

What build systems are supported? What are the project formats?

CLion fully integrates with the CMake build system: you can create, open, build and run/debug CMake projects seamlessly. CMake itself is bundled in CLion, so you don't need to install it separately unless you decide to use a custom version.

Apart from CMake, CLion supports Makefile, compilation database, and Gradle projects. Creating new projects of these types in CLion is not supported currently.

Refer to Project Formats for details.

Do I need to install anything in advance?

On Windows, CLion requires a working environment. CLion bundles a version of the MinGW toolset for quick setup. You can use this bundled toolchain or switch to another MinGW installation, Cygwin, or Microsoft Visual C++. If you are working with WSL or Docker, you will need to install them as well.

Refer to our Windows tutorial.

On macOS, the required tools might be already installed. If not, update command line developer tools as described in Configuring CLion on macOS.

On Linux, compilers and make might also be pre-installed. Otherwise, in case of Debian/Ubuntu, install the build_essentials package and, if required, the llvm package to get Clang.

Are languages other that C++ supported as well?

Yes, CLion fully supports Python, Objective-C/C++, HTML (including HTML5), CSS, JavaScript, and XML. Support for these languages is implemented via the bundled plugins, which are enabled by default. See CLion features in different languages for more details.

You can install other plugins to get more languages supported in CLion (such as Rust, Swift, or Markdown). See Valuable language plugins.

1. Open/create a project

Open a local project

Use one of the following options:

  • Select File | Open and locate the project directory.

    This directory should contain a CMakeLists.txt file.

  • Select File | Open and point CLion to the top-level CMakeLists.txt file, then click Open as Project.

  • Select File | Open and locate the CMakeCache.txt file, then click Open as Project.

  1. Select File | Open from the main menu.

  2. Point CLion to the folder containing the top-level Makefile or to Makefile itself (in this case, click Open as Project on the next step).

  1. Select File | Open from the main menu.

  2. Point CLion to the folder containing compile_commands.json or to the compile_commands.json itself (in this case, click Open as Project on the next step).

  1. Select File | Open from the main menu.

  2. Point CLion to the folder containing build.gradle or to the build.gradle file itself (in this case, click Open as Project on the next step).

    Clone a repository

    1. Click Get from VCS on the Welcome screen or select Git (or your VCS) | Clone.

    2. Enter the credentials to access the storage and provide the path to the sources.

    Create a new CMake project

    1. Select File | New Project from the main menu or click New Project on the Welcome screen.

    2. Set the type of your project: C or C++, an executable or a library.

      Note that STM32CubeMX and CUDA are also CMake-based project types.

    3. Provide the root folder location and select the language standard.

    CLion creates a new CMake project and fills in the top-level CMakeLists.txt:

    CMakeLists.txt in a stub CMake project

    The initial CMakeLists.txt file already contains several commands. Find their description and more information on working with CMake in our tutorial.

    2. Take a look around

    The IDE user interface

    Find a detailed description of the UI elements in User interface.

    Any time you need to find an IDE action, press Control+Shift+A or go to Help | Find Action and start typing the name of a command, setting, or even a UI element that you are looking for:

    search for an ide action

    3. Customize your environment

    Change the IDE appearance

    The quickest way to switch between the IDE's color schemes, code styles, keymaps, viewing modes, and look-and-feels (UI themes) is the Switch... pop-up. To invoke it, click View | Quick Switch Scheme or press Control+`:

    switch pop-up

    To explore all the customizable options, go to the dedicated pages in SettingsControl+Alt+S.

    Tune the editor

    Pages under the Editor node of the Settings dialog help you adjust the editor’s behavior, from the most general settings (like Drag'n'Drop enabling and scroll configuration) to highlighting colors and code style options.

    Code styles are configurable for each language separately in the pages under the Editor | Code Style node. For C/C++, you can set one of the predefined code styles or provide your own, and configure the desired naming convention including the header guard template:

    Naming convention settings

    Adjust the keymap

    In CLion, almost every action possible in the IDE is mapped to a keyboard shortcut. To view the default mapping, call Help | Keyboard Shortcuts PDF.

    You can customize the shortcuts in Settings| Keymap. Use one of the predefined keymaps (Visual Studio, Emacs, Eclipse, NetBeans, Xcode, and others) and tune it as required, or create your own keymap from scratch.

    There are also plugins that extend the list of available keymaps. For example, VS Code Keymap or Vim emulation (which includes the Vim keymap). Find more useful plugins for the CLion editor in Valuable non-bundled plugins.

    4. Code with assistance

    Auto-completion

    Completion Control+Space in CLion works as you type and gives a list of all available completions. To filter this list and see only the suggestions that match the expected type, use Smart completion Control+Shift+Space:

    SmartType completion

    Completion, along with other code insight features, is available for CMake code as well. See Code assistance in CMakeLists.txt.

    Completion in CMake

    Code generation

    Even an empty class or a new C/C++ file contains boilerplate code, which CLion generates automatically. For example, when you add a new class, CLion creates a header with stub code and header guard already placed inside, and the corresponding source file that includes it.

    One of the most useful code generation features is create from usage. It helps you focus on the ideas as they come up and takes care of the routine.

    For example, when you call a function that is not yet implemented, there is no need to break the flow: press Alt+Enter to generate stub code that you can come back to later. Create from usage works for variables and classes as well:

    generate code from usage

    To get the list of code generation options at any place in your code, press Alt+Insert to invoke the Generate menu:

    generate menu

    These options can help you skip a lot of code writing. In addition to generating constructors/destructors, getters/setters, and various operators, you can quickly override and implement functions:

    Implement functions

    Live templates are the tool to generate entire code constructs. Find the list of ready-to-use templates in Settings | Editor | Live Templates. To paste a template in your code, call Code | Insert Live Template or press Control+J, for example:

    live template example

    To quickly surround your code with loops and conditional statements like if, while, for, #ifdef, call Code | Surround With or press Control+Alt+T:

    surround with example

    Intentions and quick-fixes

    When you see a light bulb next to a symbol in your code, it means that CLion's code analysis has found a potential problem or a possible change to be made:

    • App actions quickfix bulb indicates an error and lets you choose a quick fix for it,

    • App actions intention bulb indicates that one or several intention actions are available.

    Click the light bulb icon (or press Alt+Enter) and choose the most suitable action or quick-fix:

    Intention actions and quick-fixes in the editor

    Inspections

    During on-the-fly code analysis, CLion highlights suspicious code and shows colored stripes in the right-hand gutter. You can hover the mouse over a stripe to view the problem description and click it to jump to the corresponding issue. The sign at the top of the gutter indicates the overall file status:

    Analysis results in the scrollbar

    CLion detects not only compilation errors but also code inefficiencies like unused variables or dead code. Also, it integrates a customizable set of Clang-tidy checks.

    To enable or disable inspections, configure their severity levels (whether an inspection should raise an error or just be shown as a warning) and set the scopes, go to Settings | Editor | Inspections.

    You can also run inspections on demand for the whole project or a custom scope, and view the results in a separate window. For this, call Code | Inspect Code or use Code | Analyze Code | Run Inspection by Name… Control+Alt+Shift+I for a particular inspection.

    From the results tool window, you can batch-apply quick fixes for several issues at a time. Click Fix partially in the description tab:

    Applying quick-fixes to several inspection results

    Refactorings

    Refactorings help improve your code without adding new functionality, making it cleaner and easier to read and maintain. Use the Refactor section of the main menu or call Refactor This... Control+Alt+Shift+T to get the list of refactorings available at the current location:

    retactor this popup

    For example:

    • Rename Shift+F6 renames a symbol in all references;

    • Change Signature Control+F6 adds, removes, or reorders function parameters, changes the return type, or updates the function name (affecting all usages);

    • Inline Control+Alt+N / Extract inlines or extracts a function, typedef, variable, parameter, define, or constant;

    • Pull Members Up/Down (Refactor | Pull Members Up / Push Members Down) safely moves class members to the base or subclass.

    5. Explore your code

    Search everywhere

    To search for anything in CLion, be it an item in your codebase, action, or UI element, press Shift twice and start typing what you are looking for in the Search Everywhere dialog. Use the filter filter menu to narrow your search:

    search everywhere popup

    Find usages

    To locate the usage of any code symbol, call Find Usages (Alt+F7 or Edit | Find | Find Usages). You can filter the results and jump back to the source code:

    find usages results

    Navigate in the code structure

    • Switch between header and source file Control+Alt+Home

    • Go to declaration/definition Control+BControl+Alt+B

    • Show file structure Alt+7

    • View type hierarchy Control+H

    • View call hierarchy Control+Alt+H

    • View import hierarchy Alt+Shift+H

    For your code, CLion builds the hierarchies of types, call, imports, and functions. To view them, use the shortcuts given above or the commands in the Navigate menu. For example, type hierarchy helps you not only to navigate the code but also to discover what type relationships exist in the your codebase:

    type hierarchy

    To explore the structure of the currently opened file, call View | Tool windows | Structure or press Alt+7:

    file structure

    Also, use the left gutter icons to quickly jump to a declaration/definition or navigate through the class hierarchy (the Implemented method icon / the Implementing method icon, the Overridden method icon / the Overriding method icon).

    Quick Documentation popup (available on mousehover or via the Control+Q shortcut) helps you get more information on a symbol at caret without leaving the current context. Depending on the element you invoke it for, the popup shows:

    • function signature details,

    • code documentation (either regular or Doxygen comments),

    • inferred types for variables declared as auto:

      C++ inferred type in Quick Documentation popup
    • formatted macro expansions:

      Formatted macro expansion in Quick Documentation popup

    Besides, you can instantly view the definition of a symbol at caret. Press Control+Shift+I to invoke the Quick Definition popup:

    Quick definition

    6. Build and run

    Run single file

    If you have only one or two files to compile and run, there is no need for you to get into project models: your files can be compiled and run/debug without it.

    1. Open a source file or folder.

    2. In the editor, click the left gutter icon next to your program's entry point and select the action:

      Run/debug a file using the gutter menu

    Run/Debug configurations

    For each target in your project, CLion creates a run/debug configuration. It is a named setup which includes target, executable, arguments to pass to the program, and other options.

    Run/Debug configurations are generated from templates, such as CMake Application, Google Test, Remote GDB Debug, and so on. The templates are customizable: when you edit a template parameter, you change the default settings of all configurations that will be created from this template later.

    Edit Configurations dialog is accessible from the Run menu or the configuration switcher. Here you can manage the templates and add, delete, or edit your configurations.

    For example, you can customize the steps to be taken Before launch: call external tools (including the remote ones), use CMake install, or even run another configuration.

    Run/debug configurations dialog - the Before launch list

    To launch your program, select the desired configuration and use commands from the App actions executeRun menu or press Shift+F10. Alternatively, invoke the Run Anything dialog by pressing Ctrl twice and start typing the configuration name:

    run anything dialog

    Build actions

    Build is included in many Run/Debug configuration templates as a default pre-launch step. However, you can also perform it separately by calling the desired action from the Build menu:

    build menu

    Notice the Recompile option that compiles a selected file without building the whole project.

    Remote and embedded development

    With CLion, you can also build and run/debug on remote machines including embedded targets. See the sections on Remote development and Embedded development.

    7. Debug

    CLion integrates with the GDB backend on all platforms (on Windows, the bundled GDB is available only for MinGW) and LLDB on macOS/Linux. You can switch to a custom version of GDB on all platforms. Also, CLion provides an LLDB-based debugger for MSVC on Windows.

    Currently, the versions of the bundled debuggers are the following:

    • LLDB v 15.0.5 for macOS/Linux and 9.0.0 for Windows (MSVC)

    • GDB v 12.1 for macOS

    • GDB v 12.1 for Windows

    • GDB v 12.1 for Linux

    • Custom GDB v 7.8.x-12.1

    To start a debug session, select the desired configuration and press Shift+F9 or click App actions start debugger. You can set breakpoints by clicking the gutter next to a code line. To follow through the execution process, use debugger's stepping actions stepping buttons.

    In the Variables tab of the debugger tool window, you can explore the values and change them without interrupting your debug session. To evaluate an expression, click App debugger evaluate expression or press Alt+F8. CLion also shows the current variables' values right in the editor, and in case you enable hex view, it is shown inlined as well:

    clion debugger ui

    Useful debugger shortcuts

    Toggle breakpoint

    Control+F8

    View breakpoint details/all breakpoints

    Control+Shift+F8

    Step over

    F8

    Step into

    F7

    Stop

    Control+F2

    Resume program

    F9

    Debug code at caret

    Shift+F9 within main()

    Besides, you can step into disassembly, invoke Memory view, attach to a local process, and debug remotely using GDB/gdbserver.

    8. Analyze at run-time

    Some vulnerabilities and bugs can only be revealed during the program's execution: memory leaks, uninitialized accesses, concurrency issues, undefined behavior, and others.

    To help you catch run-time problems, CLion integrates Valgrind Memcheck and Google Sanitizers.

    Also, you can analyze your application performance using the built-in CPU Profiler and measure code coverage. For these tools, CLion provides visualized output and handy features like the option to import/export analysis results.

    Settings for Valgrind, Sanitizers, and Profile are located under Settings | Build, Execution, Deployment | Dynamic Analysis Tools.

    See the section on Dynamic code analysis for details.

    Valgrind Memcheck

    Valgrind Memcheck in CLion works on Linux, macOS, and Windows via WSL. You need to install Valgrind, point CLion to the binary, set up the analysis flags, and run the program using Run | Run Valgrind Memcheck or App actions start memory profile.

    Google Sanitizers

    Google Sanitizers are supported on Linux for certain versions of Clang and GCC. Take a look at our detailed guide on using Sanitizers in CLion.

    CPU Profiler

    CLion’s profiler, available on Linux and macOS, collects performance data for both user and kernel code of your application. The profiler collects performance metrics and visualizes them in flame charts and statistic views. To run it, call Run | Profile or use the App toolwindows tool window profiler button in the navigation bar.

    Code Coverage

    Code Coverage integration in CLion is based on llvm-cov/gcov tools and is available for CMake applications and tests. Coverage results show the percentage of files per folder and lines per file covered during a launch. To get coverage measurements, set the necessary compiler flags and call Run with Coverage or click App general run with coverage.

    9. Add unit tests

    CLion supports Google Test, Boost.Test, Catch(2), CTest, and Doctest testing frameworks with the built-in test runner and dedicated Run/Debug configurations. For CMake targets linked with gtest or gmock, CLion creates Google Test configurations automatically.

    Running tests is similar to running a regular executable: CLion passes the specified test classes or methods to the test runner. Test runner shows the progress bar, output stream, and tree view of the running tests, and indicates their status and duration:

    test runner

    You can rerun particular tests, all of them, or only the failed ones App run configurations rerun failed tests, export test results and open previous results from the history.

    Icons in the left gutter help you quickly run/debug tests and check the test status, success App run configurations test state green2 or failure App run configurations test state red2:

    gutter icons for running tests

    10. Keep it under version control

    VCS

    CLion integrates with several version control systems: Git (or GitHub), Mercurial, Perforce, and Subversion. To manage the settings of a particular VCS, go to Settings | Version Control.

    Use the VCS Operations Popup (Alt+` or VCS | VCS Operations Popup) to call version control commands. The list of actions in this popup includes both the currently enabled VCS and local history. For example:

    No VCS Enabled

    VCS Enabled

    Cl vcs disabled
    Cl vcs enabled

    You can find all the available VCS commands in the VCS section of the main menu. Also, some basic commands are accessible from the toolbar:

    vcs command in navigation bar

    Local history

    In addition to full version control, you can go back and review changes step by step by browsing the local history. To view it for a file or folder, call VCS | Local History | Show History. Here you can revert changes and create patches:

    local history

    11. Learn more

    We hope this brief overview of the CLion essentials will give you a quick start. To dig deeper, take a look at other articles and sections in the webhelp, for example:

    For news and useful tips, check our twitter and CLion blog.

    Feel free to ask any questions on the community forum and don't hesitate to report problems in the CLion issue tracker.

    Last modified: 11 January 2023