CLion 2024.1 Help

Cling integration

CLion integrates with Cling, an interactive C++ interpreter built on top of Clang and LLVM. Cling allows you to run code without building the project, which can be especially useful for prototyping and learning C++. See the short Cling basics video.

Install Cling

  1. Download the Cling executable for your OS or install it using a dependency manager. On macOS, use the following brew command: brew install cling.

  2. In CLion, go to Settings | Languages & Frameworks | C/C++ | Cling.

    If Cling is presented in the system PATH, CLion will detect it automatically. Otherwise, provide the path in the field.

    Path to cling executable

Use Cling to interpret code

  • You can call Cling-related actions from Tools | Cling from the main menu or via Help | Find Action (Ctrl+Shift+A).

    Cling actions menu
  • To send a line or selection to the Cling session, click the bulb icon (or press Alt+Enter) on the desired piece of code:

    Cling intention
  • Another option is to type code directly in the Cling terminal.

Working directory for a Cling session

  • If there is a file currently opened in the editor, its directory is used as a working directory for Cling. Related include paths from this file work as well when sent to the same session.

  • Otherwise, CLion uses the project root.

  • If there is no project, the home directory is used.

Cling terminal

Upon any of the Cling actions, CLion opens the dedicated terminal window.

You can type code in this window and also load the current file or reset/close the session using the toolbar buttons.

Cling terminal

    Current issues and limitations

    • Adding extra arguments to the Cling executable from within CLion is not available.

    • The Cling session is started within the project directory or within the home directory (if no project is currently open). The relative paths might not be handled correctly when sending a current line to Cling from a file that is not in the project root.

    Last modified: 11 February 2024