CLion 2023.1 Help

Compile files without build

To speed up the development process, you may sometimes prefer to compile one file without building the whole project. For this purpose, CLion provides the Recompile action.

Recompile is available for individual source and header files, and also for groups of files selected in the project tree. For headers, CLion uses resolve context to compile one of the source files that include the specified header). Note that Recompile is disabled for directories and non-C/C++ files.

Call Recompile

Use of the following options:

  • For the currently opened file, choose Build | Recompile from the main menu (or press Control+Shift+F9):

    Recompile from the main menu
  • For a file in the project tree, use the Recompile option from the right-click menu (or use the same Control+Shift+F9 shortcut):

    Recompile from the right-click menu

    For several files, select them in the project tree, and use the Recompile selected files option from the right-click menu Control+Shift+F9:

    recompile several files in the project tree
    Note that when used for multiple files, the recompilation stops upon the first compilation failure.

Compilation details

When called from a Makefile or a compilation database project, Recompile takes the compilation command found during project analysis, modifies it (skipping the output and adding the --syntax-only flag), and uses it to compile the selected file.

When you use Recompile, a CMake target is called instead of a direct compiler call. The target to call is picked based on the list of the available run/debug configurations:

  1. If the file to compile belongs to the currently selected configuration, then the build target from this configuration is used.

  2. Otherwise, CLion attempts to find a suitable configuration, prioritizing those with the same CMake profile as the currently selected one.

  3. If the previous step has failed, then CLion reports an error.

Examining the results

As with a regular build, you can examine the results of a single file compilation in the Message Tool Window:

Recompilation successful

If the compilation fails, you will get a signaling pop-up message:

Recompilation failed
Last modified: 11 January 2023