Problems linking to .dylib


I’m trying to add a .dylib to my project that in turns depends on several other libs. So far I can’t get it working in any DAW.
What I’m doing is:

  1. Copying the .dylib into the bundle at /Contents/MacOS/
  2. Adding an rpath to the program file using
    install_name_tool -add_rpath @executable_path "my-program-file"
  3. This works for the standalone version, but plugins won’t load.

Before this I simply added a sym-link of the .dylib to /usr/local/lib. Same results.
In the JUCE plugin host I see it having trouble with this line:

So how do I correctly bundle this?

Oh okay, I found the solution by myself.
In case of a plugin, @executable_path resolves to the DAWs executable. @loader_path resolves to the plugins path when its loaded inside a DAW.

So I just switched the install name of the lib back to @rpath/mylib.dylib using:

install_name_tool -id @rpath/mylib.dylib mylib.dylib

And then I add two new rpaths to the resulting executable using:

install_name_tool -add_rpath @executable_path/../Frameworks
install_name_tool -add_rpath @loader_path/../Frameworks

This way the executable looks in these two directories for the .dylib. First one is for standalone use, second one for plugins.

Last but not least, copy the actual .dylib into the bundle under Contents/Frameworks/ so it can be found.

See also: