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
Click Open on the Welcome screen or select from the main menu
You can either open a file or a folder containing one or several files:
Select the file:
Click Open as project:
Select the folder where your C/C++ file or files are located:
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.
2. Run/debug a file using the gutter menu
In the editor, click the left gutter icon next to your program's entry point:
If you select Run, the file will be compiled and run, and you will see the results in the Run tool window:
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.
To access the configuration settings, do one of the following:
Click Edit Configurations in the configuration switcher:
From the gutter menu, select Modify Run Configuration:
Go to
in the main menu, then select the configuration in the list (its name will be similar to the name of the file).
In the Edit Configuration dialog, you can adjust the settings of compilation and run. For example, add the required compiler options:
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.
Click Apply to save the changes.
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 the following:
Select the configuration in the Edit Configurations dialog and click on the toolbar:
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 Configure for the current file on top of your source file.
in the main menu or clickIn the Run/Debug Configuration dialog, click on the toolbar or press Alt+Insert. Select C/C++ File from the list of templates:
Provide the name for your configuration, select the source file, and set additional options if required.
Click Apply to save the changes.