cmake
install_error
ai_generated
true
CMake 错误:install(EXPORT "MyTargets" ...) 在导出集中多次包含了目标 "mylib"。
CMake Error: install(EXPORT "MyTargets" ...) includes target "mylib" more than once in the export set.
ID: cmake/export-duplicate-target
85%修复率
88%置信度
1证据数
2024-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| CMake 3.20 | active | — | — | — |
| CMake 3.26 | active | — | — | — |
| CMake 3.28 | active | — | — | — |
根因分析
同一个目标被多次列在写入同一导出集的 install(TARGETS ...) 命令中,或者通过 install 和 export() 调用将目标添加到了同一导出集。
English
The same target is listed in multiple install(TARGETS ...) commands that write to the same export set, or a target is added to the same export set via both install and export() calls.
解决方案
-
将所有针对同一导出集的 install(TARGETS) 合并为单个 install(TARGETS ... EXPORT MyTargets) 调用,列出所有目标。
-
使用 NAMESPACE 和带有 COMPONENT 的 install(EXPORT) 进行拆分,但确保每个目标在每个导出集中只出现一次。
无效尝试
常见但无效的做法:
-
Remove one of the install(TARGETS) lines entirely
35% 失败
If that target needs to be installed for both runtime and development, removing one line might break the install step.
-
Use different export names for each install(TARGETS) call
25% 失败
This creates separate export sets, which may not be what the downstream project expects (they'd need to include both).