Native Plugin Help Needed! Pretty please!

Hi,
I’m having trouble writing a native code plugin that uses an external shared library.

Using the example MidiPlugin, I created an Xcode bundle project with some basic functions that return strings for testing. I put this into a Plugins folder and wrote an editor script that access the plugin and all works (it returns the correct strings, no errors, etc.).

Then, in my Xcode plugin, I include a header file for a shared lib and add it to the binaries to link, but I don’t even call any functions, just include and link in a build step.

When I run Unity again, now I get a DllNotFoundException.

  • I quit and restarted Unity to be sure it picked up the latest changes
  • I tried putting the shared library inside my plugin bundle in the MacOS folder, Resources folder, and also Frameworks folder, but still has the error.
  • I tried putting the shared library in the Unity Plugins folder next to my plugin but that also didn’t work.
  • I tried renaming the dylib to bundle (as was suggested elsewhere as a way to get Unity to recognize plugins) and that didn’t work.
  • I ran otool -L on my plugin and it lists the shared library correctly, and shows no path for it (whereas the other frameworks linked in show /usr/bin/etc. in front of the library name. I take this to mean it must be running from the same directory as the plugin does.
  • The Mac system console has no error messages

Help!

How can I debug this?

Where directory do plugins execute from?

Is it even possible to call other external shared libs from within a Unity native plaguing? I’m worried that the mechanism to call it is via Mono or something and may require the shared lib to be a bundle too. But the MidiPlugin uses MacOS frameworks fine, so it should be possible.

Any help on this really appreciated. I have been banging my head on the wall and there isn’t a lot of Google results that discuss this.

Thanks!
Brett

I believe I have a good fix for this. The shared library needs to have it’s “Installation Directory” on Xcode set to @loader_path/…/Frameworks and then the shared library needs to be put into the bundle’s Frameworks directory either manually or as a build phase.

Note that I wasn’t able to use install_name_tool -rpath to change the name without rebuilding in Xcode (the command doesn’t return an error, but the plugin still got the dlllnotfoundexception).