CLion 2018.2 Help

Recompiling Single File

You may prefer to compile one file at a time without building the whole project to speed up the development process. For this purpose, CLion provides the Recompile action.

Recompile is available for individual source and header files (for the latter, 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.

Calling the Recompile action

The Recompile action is accessible in two ways:

  • For the currently opened file, choose Run | Recompile from the main menu (or press Ctrl+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 Ctrl+Shift+F9 shortcut):
    Recompile from the right-click menu

Targets selection process

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

For a failed compilation, a signaling pop-up message is displayed:

Recompilation failed
Last modified: 16 June 2018