CLion 2022.3 Help

Run/debug single file

In CLion, you can compile and run/debug a single file without creating, loading, and building a whole project. This is especially useful if you are getting started with the C or C++ language, and have only one or two files that you want to compile and run. In this case, the concept of a project model might seem too complex and redundant for you.

Follow the steps below to open, compile and run or debug a file in CLion without attaching it to any project model.

1. Open a file/folder and set initial configuration

  1. Click Open on the Welcome screen or select File | Open from the main menu:

    Opening a file/folder from the Welcome screen
  2. You can either open a file or a folder containing one or several files:

    Select the file:

    Opening a single file

    Click Open as project:

    Opening a file as project

    You will see a configuration dialog. Here you can set additional run/debug parameters.

    Initial configuration dialog

    Select the folder where your C/C++ file or files are located:

    Opening a containing folder to run single file

    The folder/file will be opened without a project model.

    On top of the source file containing main, you will see a yellow pane. You can safely ignore it and proceed with running the file from the gutter menu (see below). Optionally, you can click Configure for the current file, and CLion will open the configuration dialog.

    File or folder opened without a project model

2. Run/debug a file using the gutter menu

  1. In the editor, click the left gutter icon next to your program's entry point:

    Run/debug a file using the gutter menu
  2. If you select Run, the file will be compiled and run, and you will see the results in the Run tool window:

    Running a single file from gutter

    Similarly, you can select Debug (make sure to place breakpoints in your code beforehand), and CLion will compile the file and launch a debug session.

3. Adjust the automatically created configuration

When you use the gutter menu to run/debug a file, CLion automatically creates a run/debug configuration of the type C/C++ File. This configuration allows you to quickly configure the toolchain, manage source files, and add compilation options.

  1. To access the configuration settings, do one of the following:

    • Click Edit Configurations in the configuration switcher:

      Accessing configuration from the configs menu
    • From the gutter menu, select Modify Run Configuration:

      Accessing the config settings from the gutter menu
    • Go to Run | Edit Configurations... on the main menu, then select the configuration in the list (its name will be similar to the name of the file).

  2. In the Edit Configuration dialog, you can adjust the settings of compilation and run. For example, add the required compiler options:

    Adding compiler options to C/C++ File configuration

    By default, CLion uses cc and c++ compilers on macOS and Linux and cl.exe on Windows. If you need to change that, use Additional options | Compiler path field. Note that Docker and remote toolchains are not supported.

4. (Optional) Save the automatically created configuration

The configuration that CLion creates automatically is a temporary one and will be removed after the maximum number of temporary configurations is reached. To save it for further use, do one of the following:

  • In the configuration switcher, select Save 'configuration_name' Configuration:

    Saving a configuration from the switcher

  • Select the configuration in the Edit Configurations dialog and click Save on the toolbar:

    Saving a configuration from the dialog

5. (Optional) Add C/C++ File configurations manually

You can create more configurations of the C/C++ File type.

To access the configuration wizard, go to Run | Edit Configurations or click Configure for the current file on top of your source file.

  1. In the Run/Debug Configuration dialog, click App general add on the toolbar or press Alt+Insert. Select C/C++ File from the list of templates:

    Adding a C/C++ File configuration
  2. Provide the name for your configuration, select the source file, and set additional options if required.

Last modified: 28 December 2022