cmake install_error ai_generated true

CMake Error: install(EXPORT "MyTargets" ...) includes target "mylib" which is not in the export set.

ID: cmake/export-target-not-found

Also available as: JSON · Markdown · 中文
89%Fix Rate
86%Confidence
1Evidence
2023-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
CMake 3.14 active
CMake 3.16 active
CMake 3.22 active
CMake 3.27 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

  1. 90% success Ensure every target in install(EXPORT ...) is also installed with install(TARGETS ... EXPORT ...) using the same export set name.
    Ensure every target in install(EXPORT ...) is also installed with install(TARGETS ... EXPORT ...) using the same export set name.
  2. 85% success If the target is header-only, use install(TARGETS mylib EXPORT MyTargets) with an INTERFACE library.
    If the target is header-only, use install(TARGETS mylib EXPORT MyTargets) with an INTERFACE library.

中文步骤

  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.

Dead Ends

Common approaches that don't work:

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

    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% fail

    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% fail

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