# CMake 错误：AUTOGEN：未找到目标 'myapp' 的有效 Qt 'uic' 可执行文件

- **ID:** `cmake/autogen-uic-not-found`
- **领域:** cmake
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

Qt5/Qt6 的 AUTOMOC/AUTOUIC/AUTORCC 需要 uic 可执行文件在 PATH 中或通过 Qt5_DIR/Qt6_DIR 指定，但 uic 缺失或版本不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Qt5 5.15.2 | active | — | — |
| Qt6 6.5.0 | active | — | — |
| CMake 3.28 | active | — | — |
| CMake 3.29 | active | — | — |

## 解决方案

1. ```
   安装 Qt 开发工具：sudo apt install qtbase5-dev qtbase5-dev-tools（或 qttools5-dev 以获取 uic）。然后重新配置。
   ```
2. ```
   在 CMake 中显式设置 uic 路径：在 find_package(Qt5) 之前设置 set(QT_UIC_EXECUTABLE /usr/lib/qt5/bin/uic)。
   ```

## 无效尝试

- **Reinstall Qt and set CMAKE_PREFIX_PATH to the install root** — If only the library is installed without the development tools (uic, moc), find_package(Qt5) might succeed but uic is still missing. (30% 失败率)
- **Set CMAKE_AUTOUIC OFF and manually run uic** — Turning off AUTOUIC bypasses the error but leaves UI compilation unhandled, causing linker errors later. (40% 失败率)
