# CMake 错误：install(EXPORT "MyTargets" ...) 包含了目标 "mylib"，但该目标不在导出集中。

- **ID:** `cmake/export-target-not-found`
- **领域:** cmake
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 89%

## 根因

在 install(EXPORT ...) 中列出的目标未事先通过 install(TARGETS ...) 注册到该导出集。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CMake 3.14 | active | — | — |
| CMake 3.16 | active | — | — |
| CMake 3.22 | active | — | — |
| CMake 3.27 | active | — | — |

## 解决方案

1. ```
   Ensure every target in install(EXPORT ...) is also installed with install(TARGETS ... EXPORT ...) using the same export set name.
   ```
2. ```
   If the target is header-only, use install(TARGETS mylib EXPORT MyTargets) with an INTERFACE library.
   ```

## 无效尝试

- **Adding the target to the export set by adding it to install(EXPORT ...) without install(TARGETS ...)** — The target must be explicitly installed with install(TARGETS ...) first; just listing it in install(EXPORT ...) does not register it. (95% 失败率)
- **Removing the target from the export list, assuming it's not needed** — If the target is required by downstream projects, removing it breaks the export and causes missing dependencies. (70% 失败率)
- **Using install(TARGETS ... EXPORT MyTargets) but misspelling the export set name** — Mismatched export set names cause the target to be registered under a different set, leading to the same error. (80% 失败率)
