dylib to dylib pathing on mac osx, how to make rpath work on mac?

905 views Asked by At

We have a project which dynamically links against several dylibs. When copy the build to another mac. One need to run "otool" over the dylibs and executable in order to fix the shared library paths in them during "install".

Looks like OSX had some strange requirements for DLL to DLL pathing that made relative paths not work in them (i.e: using rpath). My questions here:

  1. what is the the normal way to ship a software on mac? i.e: when running either a .pkg or .dmg installer, how one make sure the dylibs installed are able to link against each other in relative path? the dylib path must be fixed with either the rpath or some post install scripts

  2. if we are not allowed to run a post install script to fix this, what are the other options?

1

There are 1 answers

0
Florian Zwoch On BEST ANSWER

Relative paths should work just fine. For example assume a macOS application bundle. The application lives in Contents/MacOS while the library lives in Contents/Frameworks. In this case you would relink the application's libraries to something like this @executable_path/../Frameworks/library.so. If you don't use an application bundle but have all files in the same directory simple using @executable_path should work too.

No need to use @rpath in these examples. you can use this too but it requires the application to define this path. This may be helpful if you want to distribute a library and people are supposed to link to your library. That way they can give an @rpath in their application to find the library without otool-ing them.

And you of course you make these changes before your package up your application into a .dmg or .pkg.