cmake
install_error
ai_generated
true
CMake Error: install TARGETS given no DESTINATION and no RUNTIME, ARCHIVE, LIBRARY, or BUNDLE component.
ID: cmake/install-target-destination-not-set
93%Fix Rate
90%Confidence
1Evidence
2023-09-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| CMake 3.10 | active | — | — | — |
| CMake 3.16 | active | — | — | — |
| CMake 3.25 | active | — | — | — |
Root Cause
The install(TARGETS) command must specify a destination or component for each target type; otherwise, CMake does not know where to place the installed files.
generic中文
install(TARGETS) 命令必须为每种目标类型指定目标路径或组件;否则 CMake 不知道将安装文件放在哪里。
Official Documentation
https://cmake.org/cmake/help/latest/command/install.html#install-targetsWorkarounds
-
95% success Add DESTINATION for each target type: install(TARGETS mylib RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static). Example: install(TARGETS myapp RUNTIME DESTINATION bin).
Add DESTINATION for each target type: install(TARGETS mylib RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static). Example: install(TARGETS myapp RUNTIME DESTINATION bin).
-
90% success Use a single DESTINATION for all components: install(TARGETS mylib DESTINATION lib). This works for simple libraries that don't separate runtime/archive.
Use a single DESTINATION for all components: install(TARGETS mylib DESTINATION lib). This works for simple libraries that don't separate runtime/archive.
中文步骤
为每种目标类型添加 DESTINATION:install(TARGETS mylib RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static)。示例:install(TARGETS myapp RUNTIME DESTINATION bin)。
为所有组件使用单一 DESTINATION:install(TARGETS mylib DESTINATION lib)。这适用于不分离运行时/存档的简单库。
Dead Ends
Common approaches that don't work:
-
80% fail
If a target produces both a runtime and a library, both must have destinations; specifying only one leaves the other undefined.
-
95% fail
CMAKE_INSTALL_PREFIX sets the root, but install(TARGETS) needs explicit DESTINATION relative to that root.