I’m really struggling with the RPATH issues on macOS. I think I read quite some blogposts, etc but I still cannot get it right, and I hope someone could help me a bit. So, here is the problem:
I’m trying to build an executable, Engine, which is linked to a few static libraries and some system libraries as follow.
-
Commonis a STATIC library linked toBOOST,libJSONandlibArchive. -
R-Interfaceis a STATIC library linked toCommon,libR,libRcpp, andlibRInside - and finally the
Engineis a STATIC library linked toCommon, andR-Interface.
I pull some of those packages via the find_package and some via the pkg_check_modules (e.g., libR) and link them together. So, for R-Interface I have:
target_link_libraries(
R-Interface PUBLIC
Common
PkgConfig::LIBR
${_LIB_RCPP}
${_LIB_RInside}
)
and ${_LIB_RCPP} and ${_LIB_RInside} are set by find_library as follow, so that they point to my system Rcpp.so and RInside.so.
find_library(_LIB_RCPP
NAMES Rcpp.so
PATHS ${_Rcpp_HOME}/libs
NO_CACHE
REQUIRED)
find_library(_LIB_RInside
NAMES RInside.so
PATHS ${_RInside_HOME}/libs
NO_CACHE
REQUIRED)
Now, the problem is when I build everything and run the Engine, I see that the Engine cannot find the Rcpp.so,
dyld[41231]: Library not loaded: Rcpp.so
Referenced from: build/Engine
Reason: tried: 'Rcpp.so' (no such file), '/usr/local/lib/Rcpp.so' (no such file), '/usr/lib/Rcpp.so' (no such file), '/Users/amabdol/Projects/JASP/jasp-desktop/build/Rcpp.so' (no such file), '/usr/local/lib/Rcpp.so' (no such file), '/usr/lib/Rcpp.so' (no such file)
I started reading and I realized that I should add the RPATH on macOS and I added these in an attempt to add the RPATH to the binary.
set(CMAKE_SKIP_BUILD_RPATH OFF)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(CMAKE_INSTALL_RPATH "/opt/homebrew/lib/R/4.1/site-library/Rcpp/libs/;/opt/homebrew/lib/R/4.1/site-library/RInside/libs/")
set(CMAKE_BUILD_RPATH "/opt/homebrew/lib/R/4.1/site-library/Rcpp/libs/;/opt/homebrew/lib/R/4.1/site-library/RInside/libs/")
However, I still get the error, and I don’t know why, especially because I see that LC_RPATH is set both in otool -l Engine and otool -l R-Interface.
libR-Interface.dylib and Engine:
Load command 27
cmd LC_RPATH
cmdsize 64
path /usr/opt/homebrew/lib/R/4.1/site-library/Rcpp/libs/ (offset 12)
Load command 28
cmd LC_RPATH
cmdsize 64
path /usr/opt/homebrew/lib/R/4.1/site-library/Rcpp/ (offset 12)
however, the otool -L R-Interface still looks off, right?
R-Interface/libR-Interface.dylib:
@rpath/libR-Interface.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/boost/lib/libboost_nowide-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/boost/lib/libboost_filesystem-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/boost/lib/libboost_system-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/boost/lib/libboost_date_time-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/boost/lib/libboost_timer-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/boost/lib/libboost_chrono-mt.dylib (compatibility version 0.0.0, current version 0.0.0)
Rcpp.so (compatibility version 0.0.0, current version 0.0.0)
RInside.so (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/libarchive/lib/libarchive.13.dylib (compatibility version 19.0.0, current version 19.2.0)
/opt/homebrew/opt/jsoncpp/lib/libjsoncpp.24.dylib (compatibility version 24.0.0, current version 24.0.0)
/opt/homebrew/opt/r/lib/R/lib/libR.dylib (compatibility version 4.1.0, current version 4.1.1)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1200.3.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
I am not really sure what I am missing at this point, so, any help will be appreciated! 

