I’m linking to an external library /abs/path/lib/libexternal.dylib. The dylib has it’s -install_name/Library ID set to the relative path "lib/libexternal.dylib".
When I link to this from my downstream application, it fails to load the library at run-time, unless I run from the cwd or /abs/path, because regardless of how I seem to give the dyld to the linker the “dependent library install name” is copied directly:
$ otool -L test.so
test.so:
test.so (compatibility version 0.0.0, current version 0.0.0)
lib/libexternal.dylib (compatibility version 0.0.0, current version 0.0.0)
Setting CMake _RPATH* flags was my first attempt at solving, but doesn’t touch the problem, because this relationship appears to be handled by the linker/loader directly.
Assuming that I cannot “fix” the upstream library on a short timescale (which gets around this by setting DYLD_LIBRARY_PATH in all of their scripts), how can I work around this problem in CMake?
Are my only options either fixing upstream, or adding a custom install_name_tool compilation step that corrects the search path of my module (to e.g. either absolute or @rpath/)?