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

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

https://cmake.org/cmake/help/latest/command/install.html#export

解决方案

  1. 确保目标使用相同的 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)。
  2. 如果目标不应被导出,将其从 install(EXPORT) 调用中移除,或为其创建单独的导出集。

无效尝试

常见但无效的做法:

  1. 90% 失败

    CMake uses the EXPORT name to group targets; mismatched names cause the target to be omitted from the set.

  2. 95% 失败

    Without the export, other projects cannot use find_package to locate the installed targets.