cmake install_error ai_generated true

CMake 错误:安装 RPATH 文件 /usr/local/lib/libfoo.so 在构建树中未找到。RPATH 设置可能不正确。

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

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
1证据数
2023-09-05首次发现

版本兼容性

版本状态引入弃用备注
CMake 3.0+ active
Linux x86_64 active

根因分析

目标的 INSTALL_RPATH 属性引用了构建树中不存在的库路径,通常是因为拼写错误或使用了主机系统的绝对路径而非构建相对路径。

English

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

官方文档

https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html

解决方案

  1. 更正 INSTALL_RPATH 属性以使用构建相对路径。例如,如果库在 ${CMAKE_BINARY_DIR}/lib 中,设置:set_target_properties(mytarget PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")。
  2. 使用生成器表达式条件设置 RPATH:set_target_properties(mytarget PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")。这使用了已安装二进制文件的位置。
  3. 移除错误的 INSTALL_RPATH 并依赖 CMake 的默认 RPATH 处理:直接删除 set_target_properties 行并重新配置。

无效尝试

常见但无效的做法:

  1. Set CMAKE_SKIP_RPATH to ON to skip RPATH processing entirely 70% 失败

    Skips the check but may cause runtime failures because the installed binary cannot find its shared libraries.

  2. Manually create the missing file as a symlink 85% 失败

    The build tree is ephemeral; symlinks break after clean build. Also, the error is about the path not existing, not the file.

  3. Change INSTALL_RPATH to use $ORIGIN (relative path) 50% 失败

    While this is a good practice, simply changing to $ORIGIN without correcting the actual path still fails if the path is malformed.