Since DYLD_LIBRARY_PATH is ignored when SIP is active I am trying to use @rpath instead. I understood that one can add several @rpath and that the system will try all of them successively to find the library. I also understood that RPATHs propagate from loader to libraries and dependencies. Am I right ?
Unfortunately all my attempts to use RPATH failed so far. The auxiliary binary (embedded binary) "grasp" tries to access libraries located in a folder external to the bundle (see a description of the bundle at the end).
Here the environment variable which works if SIP is not used:
DYLD_LIBRARY_PATH="." DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/Applications/MATLAB/MATLAB_Runtime/v911/runtime/maci64" DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/Applications/MATLAB/MATLAB_Runtime/v911/bin/maci64" DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/Applications/MATLAB/MATLAB_Runtime/v911/sys/os/maci64"
Here at the bottom, the RPATH I added to the binary "grasp" using command:
install_name_tool -add_rpath <absolute path> grasp
otool -L grasp.app/Contents/MacOS/grasp
@rpath/libmwlaunchermain.dylib (compatibility version 0.0.0, current version 0.0.0)
otool -l grasp.app/Contents/MacOS/grasp | grep -B 1 -A 2 LC_RPATH
Load command 19
cmd LC_RPATH
cmdsize 32
path @loader_path (offset 12) <-- present in the original binary
--
--
Load command 20
cmd LC_RPATH
cmdsize 32
path @loader_path/. (offset 12) <-- present in the original binary
--
--
Load command 24
cmd LC_RPATH
cmdsize 64
path /Applications/MATLAB/MATLAB_Runtime/v911/bin/maci64 (offset 12)
Nonetheless I still get the error message:
dyld: Library not loaded: @rpath/libmwlaunchermain.dylib
Referenced from: grasp.app/Contents/MacOS/grasp
Reason: image not found
I thought that
@rpath/libmwlaunchermain.dylib
would resolve to the path to the library
/Applications/MATLAB/MATLAB_Runtime/v911/bin/maci64/libmwlaunchermain.dylib
Why does this fails? Is this due to "grasp" being an auxiliary binary? How can I debug that?
Bundle organisation:
Grasp4Mac.app
Contents
MacOS/mylauncher <-- launches grasp.app
Resources
Grasp/graps.app <-- embedded bundle
Contents
MacOS
applauncher <-- main
prelaunch
grasp <-- auxiliary binary calling the libraries