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-target-not-found

其他格式: JSON · Markdown 中文 · English
89%修复率
86%置信度
1证据数
2023-11-05首次发现

版本兼容性

版本状态引入弃用备注
CMake 3.14 active
CMake 3.16 active
CMake 3.22 active
CMake 3.27 active

根因分析

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

English

A target listed in install(EXPORT ...) was not previously registered with install(TARGETS ...) for that export set.

generic

官方文档

https://cmake.org/cmake/help/latest/command/install.html#exporting-targets

解决方案

  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.

无效尝试

常见但无效的做法:

  1. Adding the target to the export set by adding it to install(EXPORT ...) without install(TARGETS ...) 95% 失败

    The target must be explicitly installed with install(TARGETS ...) first; just listing it in install(EXPORT ...) does not register it.

  2. Removing the target from the export list, assuming it's not needed 70% 失败

    If the target is required by downstream projects, removing it breaks the export and causes missing dependencies.

  3. Using install(TARGETS ... EXPORT MyTargets) but misspelling the export set name 80% 失败

    Mismatched export set names cause the target to be registered under a different set, leading to the same error.