cmake
install_error
ai_generated
true
CMake Error: install(EXPORT "MyTargets") includes target "mylib" which is not in the export set.
ID: cmake/export-import-target-not-found
92%Fix Rate
86%Confidence
1Evidence
2023-12-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| CMake 3.10 | active | — | — | — |
| CMake 3.15 | active | — | — | — |
| CMake 3.22 | active | — | — | — |
Root Cause
An install(EXPORT) command references a target that was not previously registered with install(TARGETS) and the same EXPORT name.
generic中文
install(EXPORT) 命令引用的目标之前没有使用相同的 EXPORT 名称通过 install(TARGETS) 注册。
Official Documentation
https://cmake.org/cmake/help/latest/command/install.html#exportWorkarounds
-
95% success Ensure the target is installed with the same EXPORT name: install(TARGETS mylib EXPORT MyTargets DESTINATION lib). Then install(EXPORT MyTargets DESTINATION lib/cmake). Example: install(TARGETS mylib EXPORT MyTargets DESTINATION lib) and install(EXPORT MyTargets DESTINATION lib/cmake/MyProject).
Ensure the target is installed with the same EXPORT name: install(TARGETS mylib EXPORT MyTargets DESTINATION lib). Then install(EXPORT MyTargets DESTINATION lib/cmake). Example: install(TARGETS mylib EXPORT MyTargets DESTINATION lib) and install(EXPORT MyTargets DESTINATION lib/cmake/MyProject).
-
85% success If the target should not be exported, remove it from the install(EXPORT) call or create a separate export set for it.
If the target should not be exported, remove it from the install(EXPORT) call or create a separate export set for it.
中文步骤
确保目标使用相同的 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) 调用中移除,或为其创建单独的导出集。
Dead Ends
Common approaches that don't work:
-
90% fail
CMake uses the EXPORT name to group targets; mismatched names cause the target to be omitted from the set.
-
95% fail
Without the export, other projects cannot use find_package to locate the installed targets.