Skip to content

Commit b549840

Browse files
committed
ENH: Add relative path to lib directory to RPATH on Linux and MacOS
Addresses issue #1402, Avoid "error while loading shared libraries" on Linux
1 parent ed32a1b commit b549840

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Core/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,14 @@ set(ELASTIX_LIBRARIES elastix_lib transformix_lib PARENT_SCOPE)
277277

278278
if(ELASTIX_BUILD_EXECUTABLE AND NOT WIN32)
279279
# Tell the executables where to find the required .so files.
280-
set_target_properties(elastix_exe transformix_exe
281-
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${ITK_DIR}")
280+
# Supports having the executables in bin, and the .so files in the lib directory next to the bin.
281+
if (APPLE)
282+
set_target_properties(elastix_exe transformix_exe
283+
PROPERTIES BUILD_RPATH "@executable_path/../lib" INSTALL_RPATH "@executable_path/../lib:${CMAKE_INSTALL_PREFIX}/lib:${ITK_DIR}")
284+
else()
285+
set_target_properties(elastix_exe transformix_exe
286+
PROPERTIES BUILD_RPATH "\$ORIGIN/../lib" INSTALL_RPATH "\$ORIGIN/../lib:${CMAKE_INSTALL_PREFIX}/lib:${ITK_DIR}")
287+
endif()
282288
endif()
283289

284290
if(ELASTIX_BUILD_EXECUTABLE AND NOT ELASTIX_NO_INSTALL_EXECUTABLES)

0 commit comments

Comments
 (0)