How to include dependent dylib for Mac plugin?

The problem is not in the building of my plugin but in allowing Unity to see a 3rd party .dylib.

On Windows I solved this by making sure my code loaded both dll’s (using DllImport) and then everything worked fine. I’ve tried that approach on Mac but that appears not to have worked.

I’ve read this post and this post to no avail. Possibly because I’m not entirely sure of what I’m doing on a Mac. I’m sure this must have been solved many times over so I’m surprised there isn’t clearer docs about this.

Can you help?

Thanks.

I finally managed to achieve this. This link was extremely useful (as was this). The steps I took were:

  1. Find what the install directory for the 3rd party library is. I used otool for this. Luckily for me the library did use @loader_path.
  2. In your xCode Plugin project, in build phases add the 3rd party .dylib to link binary with libraries.
  3. Add a new “Copy Files” build phase (button bottom right “Add Build Phase”).
  4. Depending on what the 3rd party installation directory is set the Destination appropriately. In my case, since it was straight @loader__path I set it to Executable. The other common ones are @executable_path/…/Frameworks or @loader_path/…/Frameworks, in which case set it to Frameworks.
  5. Add the 3rd party .dylib to the list.
  6. Build!

The .dylib is now included in your bundle and your plugin can call functions from this 3rd party library with no issues. Note that you won’t be able to call the 3rd party library functions from Unity, or at least I couldn’t figure out how to.

I hope that helps someone, took me days to figure this all out!