Skip to content

dynamic library install problem on macOS #907

Description

@jclark

When I build and install on macOS, the installed binaries don't work:

% str2str
dyld[76494]: Library not loaded: @rpath/librtklib.dylib
  Referenced from: <9A40F8A3-2829-3625-A427-288739C63802> /usr/local/bin/str2str
  Reason: no LC_RPATH's found
zsh: abort      str2str

My coding agent tells me the right fix is:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2aa958ff..5133d4f4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,15 @@ include(CTest)

 option(IERS_MODEL "Use Earth models from IERS" OFF)

+# make installed executables locate the rtklib shared library relative to
+# themselves (<prefix>/bin -> <prefix>/lib) so the install tree is relocatable
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+if(APPLE)
+    set(CMAKE_INSTALL_RPATH "@loader_path/../lib")
+elseif(UNIX)
+    set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
+endif()
+
 set(TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/data)

 # configure rtklib

This does indeed solve the problem, and seems plausible, but I know nothing of CMake

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions