cmake install_error ai_generated true

CMake Error: install(EXPORT "MyTargets" ...) includes target "mylib" more than once in the export set.

ID: cmake/export-duplicate-target

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2024-02-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
CMake 3.20 active
CMake 3.26 active
CMake 3.28 active

Root Cause

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.

generic

中文

同一个目标被多次列在写入同一导出集的 install(TARGETS ...) 命令中,或者通过 install 和 export() 调用将目标添加到了同一导出集。

Workarounds

  1. 90% success Consolidate all install(TARGETS) for the same export set into a single install(TARGETS ... EXPORT MyTargets) call listing all targets.
    Consolidate all install(TARGETS) for the same export set into a single install(TARGETS ... EXPORT MyTargets) call listing all targets.
  2. 80% success Use the NAMESPACE and install(EXPORT) with COMPONENT to split, but ensure each target appears only once per export set.
    Use the NAMESPACE and install(EXPORT) with COMPONENT to split, but ensure each target appears only once per export set.

中文步骤

  1. 将所有针对同一导出集的 install(TARGETS) 合并为单个 install(TARGETS ... EXPORT MyTargets) 调用,列出所有目标。
  2. 使用 NAMESPACE 和带有 COMPONENT 的 install(EXPORT) 进行拆分,但确保每个目标在每个导出集中只出现一次。

Dead Ends

Common approaches that don't work:

  1. Remove one of the install(TARGETS) lines entirely 35% fail

    If that target needs to be installed for both runtime and development, removing one line might break the install step.

  2. Use different export names for each install(TARGETS) call 25% fail

    This creates separate export sets, which may not be what the downstream project expects (they'd need to include both).