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

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

## 根因

同一个目标被多次列在写入同一导出集的 install(TARGETS ...) 命令中，或者通过 install 和 export() 调用将目标添加到了同一导出集。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CMake 3.20 | active | — | — |
| CMake 3.26 | active | — | — |
| CMake 3.28 | active | — | — |

## 解决方案

1. ```
   将所有针对同一导出集的 install(TARGETS) 合并为单个 install(TARGETS ... EXPORT MyTargets) 调用，列出所有目标。
   ```
2. ```
   使用 NAMESPACE 和带有 COMPONENT 的 install(EXPORT) 进行拆分，但确保每个目标在每个导出集中只出现一次。
   ```

## 无效尝试

- **Remove one of the install(TARGETS) lines entirely** — If that target needs to be installed for both runtime and development, removing one line might break the install step. (35% 失败率)
- **Use different export names for each install(TARGETS) call** — This creates separate export sets, which may not be what the downstream project expects (they'd need to include both). (25% 失败率)
