x


How to make Unity find .dylib files?

Ok, I have 6 .dylib files built from OpenCV source code. These have respective .dll versions when deploying on Windows, which is already working without much effort.

However, I can't seem to understand how to make Unity find my .dylib files on OSX. The .NET wrapper fails with DllNotFoundException because it can't find the native OSX files, I guess.

The docs talk about .bundle files built with XCode. I have tried this, and even though I add the .dylib files as external frameworks, I seem to always end up with semi-empty .bundle files not containing the .dylib files that I added to the project. I read something about using install_name_tool to modify the bundles, but it's really confusing and I'm not quite sure about the interdependencies among these .dylib files. Do you really have to do this manually?

What's the simplest possible way to make Unity find the .dylib files? Can someone please shine some light on this seemingly super-obscure subject?

Is there not a tool to simply build a bundle with .dylib files that Unity will function with? Why is it so complex on OSX, when on Windows you just dump the dll files in the Plugins directory?

more ▼

asked Jul 28 '10 at 11:41 PM

Magnus Wolffelt gravatar image

Magnus Wolffelt
457 9 11 26

Also, I have tried to use configuration xml files as instructed by: http://www.mono-project.com/Interop_with_Native_Libraries

..without much success. Anyone know if Mono config files like these work in Unity?

Jul 29 '10 at 12:32 AM Magnus Wolffelt

I'm still watching this question. I've tried building a bundle with Xcode, with a project generated from CMake. But all I get is and empty .bundle file, even though I added the dylibs as dependencies. Any help appreciated - I'm very inexperienced with OSX development.

Aug 04 '10 at 12:47 PM Magnus Wolffelt
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Ok I think I've worked out a solution. This might save some people a LOT of time and headaches:

Renaming a .dylib file to .bundle makes Unity find and load it, and it works! Weird? Yes.

Well, according to a post I found, on modern OSX, dylib and bundle are in practice interchangable, as they nowadays support mostly the same features (loading and unloading with dlopen() and dlclose()):

  • The modern dlopen implementation on the Mac (it wasn't there at all in 10.0) seems capable of loading both "bundles" (the file version I think) and regular Mac shared libraries. In 10.4, dlclose() couldn't unload a dynamic library but could unload a bundle; in 10.5, it can unload both. So it's unclear how relevant the distinction between "loadable objects" and "shared libraries" is any more, at least if you're targeting 10.5 or 10.6 as your minimum required OS version.

http://www.mail-archive.com/bug-guile@gnu.org/msg04999.html

Sooo... the limitation seems to be a Unity one in that it simply does not consider .dylib files for loading - only .bundle files, but when it does load .bundle files which happen to be dylib files, OSX just swallows it.. It could also be that this only works in Unity 3.0 - haven't tried in older versions.

Happy coding! Feel free to comment!

more ▼

answered Aug 04 '10 at 02:27 PM

Magnus Wolffelt gravatar image

Magnus Wolffelt
457 9 11 26

Actually, something sketchy is going on here. I've fiddled a lot with the install_name_tool to set paths. The most useful one so far appears to be @rpath. But it's working randomly. If it works, and I restart Unity, it can simply stop working. No idea why it's so random.

Aug 04 '10 at 06:09 PM Magnus Wolffelt

I gave up on this and just installed the dylibs into /usr/lib ...

Aug 05 '10 at 09:38 AM Magnus Wolffelt

..after putting @rpath/ on all the cross-references using install_name_tool.

Aug 05 '10 at 09:38 AM Magnus Wolffelt

Major thanks for mentioning this.

This worked pretty well for me in the editor. However, it caused the exporter to just choke with an error:

Error building Player: IOException: Cannot create Temp/StagingArea/UnityPlayer.app/Contents/Plugins/mylib.bundle/mylib.bundle because a file with the same name already exists.

the solution was, when doing the export, to move the library out of the plugins folder, and then to manually copy it into the Contents/Plugins/ directory in the application bundle myself once it had been built. May try to automate :)

Apr 16 '12 at 12:59 PM increpare
(comments are locked)
10|3000 characters needed characters left

AFAIK, there is no way to convert dylibs to bundles, and you are correct that Unity will need bundles to load native C++ code on Mac OS X. You need to have the XCode project used to generate the dylib files, and reconfigure that to output bundles.

more ▼

answered Jul 29 '10 at 09:22 AM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.7k 7 23 102

Does each .dylib file need to be in its own bundle? Or can I put all 6 of my dylib files in one bundle, and Unity will find them with DllImport?

Jul 29 '10 at 10:10 AM Magnus Wolffelt

That should not matter, if you have one bundle built from all the original source files used to build the 6 dylib files, thus containing all the needed code, then that should work fine.

Jul 29 '10 at 10:34 AM jonas echterhoff ♦♦

This won't work I think, because the .NET wrapper does DllImport with very specific library names, such as cxcore210 and cv210. I don't really have control over the wrapper code, for all practical purposes.

Jul 29 '10 at 12:38 PM Magnus Wolffelt
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x231
x85
x83
x25
x5

asked: Jul 28 '10 at 11:41 PM

Seen: 3488 times

Last Updated: Apr 16 '12 at 12:59 PM