cmake
install_error
ai_generated
true
CMake Error: install RPATH file /usr/local/lib/libfoo.so not found in build tree. RPATH settings may be incorrect.
ID: cmake/install-rpath-missing
80%Fix Rate
87%Confidence
1Evidence
2023-09-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| CMake 3.0+ | active | — | — | — |
| Linux x86_64 | active | — | — | — |
Root Cause
The INSTALL_RPATH property of a target references a library path that does not exist in the build tree, often due to a typo or using an absolute path from the host system instead of a build-relative path.
generic中文
目标的 INSTALL_RPATH 属性引用了构建树中不存在的库路径,通常是因为拼写错误或使用了主机系统的绝对路径而非构建相对路径。
Official Documentation
https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.htmlWorkarounds
-
90% success Correct the INSTALL_RPATH property to use build-relative paths. For example, if the library is in ${CMAKE_BINARY_DIR}/lib, set: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib").
Correct the INSTALL_RPATH property to use build-relative paths. For example, if the library is in ${CMAKE_BINARY_DIR}/lib, set: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"). -
95% success Use generator expressions to set RPATH conditionally: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "$ORIGIN/../lib"). This uses the installed binary's location.
Use generator expressions to set RPATH conditionally: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "$ORIGIN/../lib"). This uses the installed binary's location.
-
80% success Remove the incorrect INSTALL_RPATH and rely on CMake's default RPATH handling: just remove the set_target_properties line and reconfigure.
Remove the incorrect INSTALL_RPATH and rely on CMake's default RPATH handling: just remove the set_target_properties line and reconfigure.
中文步骤
更正 INSTALL_RPATH 属性以使用构建相对路径。例如,如果库在 ${CMAKE_BINARY_DIR}/lib 中,设置:set_target_properties(mytarget PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")。使用生成器表达式条件设置 RPATH:set_target_properties(mytarget PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")。这使用了已安装二进制文件的位置。
移除错误的 INSTALL_RPATH 并依赖 CMake 的默认 RPATH 处理:直接删除 set_target_properties 行并重新配置。
Dead Ends
Common approaches that don't work:
-
Set CMAKE_SKIP_RPATH to ON to skip RPATH processing entirely
70% fail
Skips the check but may cause runtime failures because the installed binary cannot find its shared libraries.
-
Manually create the missing file as a symlink
85% fail
The build tree is ephemeral; symlinks break after clean build. Also, the error is about the path not existing, not the file.
-
Change INSTALL_RPATH to use $ORIGIN (relative path)
50% fail
While this is a good practice, simply changing to $ORIGIN without correcting the actual path still fails if the path is malformed.