Skip to content

Commit 1caaf55

Browse files
committed
Sudden library issues (JIBAL symbols not found) on macOS in executables installed to /usr/local using make install. Probably rpath related, hard to diagnose. Found some magic words from CMake website that seem to alleviate the issue. Could be a JIBAL problem more than a JaBS problem. This Apple-specific fix shouldn't have major regressions.
1 parent 7586f52 commit 1caaf55

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

rpathmagic.cmake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#One day after "make install" everything worked on macOS. The next day dyld complains "Symbol not found" when trying to run an executable that uses JIBAL and is installed in /usr/local/bin. This made people angry and sad.
2+
# 1. JIBAL dylib does have the symbols.
3+
# 2. Old (previously compiled) executables work, new ones don't. Same JIBAL library is installed, old versions have been removed.
4+
# 3. "otool -L" says "@rpath/libjibal.0.dylib" for both old and new executables.
5+
# 4. "otool -l" doesn't list any LC_RPATHs for the old executables (that still work) nor for the new ones (that don't work).
6+
# 5. CMake is updated to latest version (3.27.5). No difference. Apple clang version 15.0.0 (clang-1500.0.40.1) Target: x86_64-apple-darwin22.6.0
7+
#
8+
# So after a lot of googling we have a temporary fix. This file. Hopefully this fix doesn't break anything else. It should essentially just put the installation prefix (e.g. /usr/local) to rpath in some cases. Like in my case.
9+
10+
#The following is directly from https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling (accessed Sep 19 2023)
11+
12+
# use, i.e. don't skip the full RPATH for the build tree
13+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
14+
15+
# when building, don't use the install RPATH already
16+
# (but later on when installing)
17+
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
18+
19+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
20+
21+
# add the automatically determined parts of the RPATH
22+
# which point to directories outside the build tree to the install RPATH
23+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
24+
25+
# the RPATH to be used when installing, but only if it's not a system directory
26+
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
27+
if("${isSystemDir}" STREQUAL "-1")
28+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
29+
endif("${isSystemDir}" STREQUAL "-1")

src/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ if(WIN32)
2323
find_library(GETOPT_LIBRARY getopt)
2424
endif()
2525

26+
if(APPLE)
27+
include(../rpathmagic.cmake) # Maybe a temporary fix to some library issues
28+
endif ()
29+
2630
add_executable(jabs
2731
main.c
2832
sample.c brick.c ion.c simulation.c reaction.c options.c
@@ -39,6 +43,7 @@ add_executable(jabs
3943

4044
target_include_directories(jabs PRIVATE ${GETOPT_INCLUDE_DIR})
4145

46+
4247
target_link_libraries(jabs
4348
PRIVATE jibal
4449
PRIVATE GSL::gsl
@@ -51,7 +56,6 @@ if(OpenMP_C_FOUND)
5156
target_link_libraries(jabs PUBLIC OpenMP::OpenMP_C)
5257
endif()
5358

54-
5559
install(TARGETS jabs RUNTIME DESTINATION bin)
5660

5761
if(0)

0 commit comments

Comments
 (0)