cmake install_error ai_generated true

CMake Error: install RPATH file /usr/local/lib/libfoo.so not found in build tree.

ID: cmake/install-rpath-not-found

Also available as: JSON · Markdown · 中文
85%Fix Rate
83%Confidence
1Evidence
2023-11-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
CMake 3.10 active
CMake 3.14 active
CMake 3.20 active

Root Cause

The INSTALL_RPATH property of a target references a file path that does not exist in the build directory, often due to a missing dependency build or incorrect path variable expansion.

generic

中文

目标的 INSTALL_RPATH 属性引用了构建目录中不存在的文件路径,通常是由于缺少依赖构建或路径变量展开不正确。

Official Documentation

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

Workarounds

  1. 90% success Correct the INSTALL_RPATH target property to use a valid build-tree path, e.g., `set_target_properties(mylib PROPERTIES INSTALL_RPATH "${CMAKE_BINARY_DIR}/lib")`.
    Correct the INSTALL_RPATH target property to use a valid build-tree path, e.g., `set_target_properties(mylib PROPERTIES INSTALL_RPATH "${CMAKE_BINARY_DIR}/lib")`.
  2. 85% success Ensure the referenced library is built before the target by adding a dependency: `add_dependencies(mylib libfoo)`.
    Ensure the referenced library is built before the target by adding a dependency: `add_dependencies(mylib libfoo)`.
  3. 80% success Use generator expressions in INSTALL_RPATH to conditionally include paths only when they exist, e.g., `$<TARGET_FILE_DIR:libfoo>`.
    Use generator expressions in INSTALL_RPATH to conditionally include paths only when they exist, e.g., `$<TARGET_FILE_DIR:libfoo>`.

中文步骤

  1. 更正 INSTALL_RPATH 目标属性以使用有效的构建树路径,例如 `set_target_properties(mylib PROPERTIES INSTALL_RPATH "${CMAKE_BINARY_DIR}/lib")`。
  2. 通过添加依赖确保引用的库在目标之前构建:`add_dependencies(mylib libfoo)`。
  3. 在 INSTALL_RPATH 中使用生成器表达式有条件地包含路径(仅当存在时),例如 `$<TARGET_FILE_DIR:libfoo>`。

Dead Ends

Common approaches that don't work:

  1. Setting CMAKE_PREFIX_PATH to include the missing library directory 75% fail

    Adding the missing library path to CMAKE_PREFIX_PATH does not affect INSTALL_RPATH, which is a target property, not a find_package search path.

  2. Creating a symbolic link in the build tree to the missing library 90% fail

    Manually creating a symlink in the build directory may bypass the error but will break on clean builds or different systems.

  3. Setting CMAKE_SKIP_RPATH to ON to skip RPATH installation 70% fail

    Disabling RPATH entirely with CMAKE_SKIP_RPATH removes the error but causes runtime linking failures on systems without the library in standard paths.