# 无需构建即可编译文件

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/clion/llms.txt).

> **TL;DR**
> `构建 | 重新编译`

为了加快开发过程，您有时可能更倾向于在不构建整个项目的情况下编译单个文件。 为此，CLion 提供了   重新编译  操作。

重新编译  可用于单个源文件和头文件，也可用于项目树中选定的文件组。 对于页眉，CLion 使用 [解析上下文](switching-resolve-context.html)来编译包含指定页眉的源文件之一）。 请注意，   重新编译  对目录和非 C/C++ 文件是禁用的。

> **Tip:**
> 您可以将   重新编译  用于 [CMake](quick-cmake-tutorial.html)、 [Makefile](makefiles-support.html)、 [Meson](meson.html)和 [编译数据库](compilation-database.html)项目。

Procedure: 调用 Recompile

使用以下选项：

* 对于当前打开的文件，请从主菜单中选择  `构建 | 重新编译` 或按 `Ctrl+Shift+F9` (Windows), `⌘ ⇧ F9` (macOS), `⌘ ⇧ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F9` (macOS System Shortcuts), `Ctrl+Shift+F9` (XWin), `Ctrl+Shift+F9` (GNOME), `Ctrl+Shift+F9` (KDE), `Ctrl+Shift+F9` (Emacs), `Ctrl+B` (Sublime Text), `⌘ B` (Sublime Text (macOS)), `⌘ ⇧ F9` (Xcode), `Ctrl+F7` (Visual Studio), `⌘ F7` (Visual Studio (macOS)), `Ctrl+F7` (ReSharper), `⌘ F7` (ReSharper (macOS)), `Ctrl+Alt+B` (QtCreator), `⌘ ⌥ B` (QtCreator (macOS)), `F9` (NetBeans), `Ctrl+Shift+F9` (Eclipse), `⌘ ⇧ F9` (Eclipse (macOS))：

![从主菜单中重新编译](https://resources.jetbrains.com/help/img/idea/2026.3/cl_recompile_mainmenu.png)

* 对于项目树中的文件，从上下文菜单中选择   重新编译  （或使用相同的 `Ctrl+Shift+F9` (Windows), `⌘ ⇧ F9` (macOS), `⌘ ⇧ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F9` (macOS System Shortcuts), `Ctrl+Shift+F9` (XWin), `Ctrl+Shift+F9` (GNOME), `Ctrl+Shift+F9` (KDE), `Ctrl+Shift+F9` (Emacs), `Ctrl+B` (Sublime Text), `⌘ B` (Sublime Text (macOS)), `⌘ ⇧ F9` (Xcode), `Ctrl+F7` (Visual Studio), `⌘ F7` (Visual Studio (macOS)), `Ctrl+F7` (ReSharper), `⌘ F7` (ReSharper (macOS)), `Ctrl+Alt+B` (QtCreator), `⌘ ⌥ B` (QtCreator (macOS)), `F9` (NetBeans), `Ctrl+Shift+F9` (Eclipse), `⌘ ⇧ F9` (Eclipse (macOS))快捷键）：

![从右键菜单中重新编译](https://resources.jetbrains.com/help/img/idea/2026.3/cl_recompile_rightclick.png)

对于多个文件，在项目树中选择它们，并从上下文菜单中使用   重新编译选定的文件  选项 `Ctrl+Shift+F9` (Windows), `⌘ ⇧ F9` (macOS), `⌘ ⇧ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F9` (macOS System Shortcuts), `Ctrl+Shift+F9` (XWin), `Ctrl+Shift+F9` (GNOME), `Ctrl+Shift+F9` (KDE), `Ctrl+Shift+F9` (Emacs), `Ctrl+B` (Sublime Text), `⌘ B` (Sublime Text (macOS)), `⌘ ⇧ F9` (Xcode), `Ctrl+F7` (Visual Studio), `⌘ F7` (Visual Studio (macOS)), `Ctrl+F7` (ReSharper), `⌘ F7` (ReSharper (macOS)), `Ctrl+Alt+B` (QtCreator), `⌘ ⌥ B` (QtCreator (macOS)), `F9` (NetBeans), `Ctrl+Shift+F9` (Eclipse), `⌘ ⇧ F9` (Eclipse (macOS))：

![在项目树中重新编译多个文件](https://resources.jetbrains.com/help/img/idea/2026.3/cl_recompile_selection.png)

> **Note:**
> 当用于多个文件时，重新编译在第一个编译失败时停止。

## 编译详情

Makefile / 编译数据库:

当从 Makefile 或编译数据库项目中调用时，   重新编译  会使用项目分析期间找到的编译命令，修改它（跳过输出并添加  `--syntax-only` 标志），并使用它来编译选定的文件。

使用旧版生成器的 CMake:

> **Note:**
> 以下描述的详情适用于您在以下情况下使用   默认 CMake 生成器  ：
>
> * 您的 CMake 版本为 3.19 或更早版本
>
> * 或者您在 `设置 | 高级设置` 中勾选了 对于 CMake 3.20 及更高版本使用旧版生成器 复选框

当您使用   重新编译  时，会调用一个 CMake 目标，而不是直接调用编译器。 要调用的目标是根据可用的 [运行/调试配置](run-debug-configuration.html)列表选择的：

1.  如果要编译的文件属于当前选定的配置，则使用该配置中的构建目标。

2.  否则，CLion 会尝试找到一个合适的配置，优先选择与当前选定配置具有相同 CMake 配置文件的配置。

3.  如果前一步失败，则 CLion 会报告错误。

## 检查结果

与常规构建类似，您可以在 [消息工具窗口](message-tool-window.html)中检查单个文件编译的结果：

![重新编译成功](https://resources.jetbrains.com/help/img/idea/2026.3/cl_recompile_success.png)

如果编译失败，您将收到一个提示弹窗消息：

![重新编译失败](https://resources.jetbrains.com/help/img/idea/2026.3/cl_recompile_fail.png)

## See also

### 操作指南

[Build Actions](build-actions.html) [Run/Debug Configurations](run-debug-configuration.html)

