cmake
install_error
ai_generated
true
CMake 错误:install(EXPORT "MyTargets") 包含目标 "mylib",但该目标不在导出集中。
CMake Error: install(EXPORT "MyTargets") includes target "mylib" which is not in the export set.
ID: cmake/export-import-target-not-found
92%修复率
86%置信度
1证据数
2023-12-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| CMake 3.10 | active | — | — | — |
| CMake 3.15 | active | — | — | — |
| CMake 3.22 | active | — | — | — |
根因分析
install(EXPORT) 命令引用的目标之前没有使用相同的 EXPORT 名称通过 install(TARGETS) 注册。
English
An install(EXPORT) command references a target that was not previously registered with install(TARGETS) and the same EXPORT name.
官方文档
https://cmake.org/cmake/help/latest/command/install.html#export解决方案
-
确保目标使用相同的 EXPORT 名称安装:install(TARGETS mylib EXPORT MyTargets DESTINATION lib)。然后 install(EXPORT MyTargets DESTINATION lib/cmake)。示例:install(TARGETS mylib EXPORT MyTargets DESTINATION lib) 和 install(EXPORT MyTargets DESTINATION lib/cmake/MyProject)。
-
如果目标不应被导出,将其从 install(EXPORT) 调用中移除,或为其创建单独的导出集。
无效尝试
常见但无效的做法:
-
90% 失败
CMake uses the EXPORT name to group targets; mismatched names cause the target to be omitted from the set.
-
95% 失败
Without the export, other projects cannot use find_package to locate the installed targets.