Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Magnus Wolffelt · Jul 28, 2010 at 11:41 PM · dllpluginsosxopencvdylib

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?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Magnus Wolffelt · Jul 29, 2010 at 12:32 AM 0
Share

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 $$anonymous$$ono config files like these work in Unity?

avatar image Magnus Wolffelt · Aug 04, 2010 at 12:47 PM 0
Share

I'm still watching this question. I've tried building a bundle with Xcode, with a project generated from C$$anonymous$$ake. 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.

avatar image amirebrahimi_unity · Aug 19, 2015 at 06:19 PM 0
Share

Additionally, you can simply drop your dylib in the root of your project folder and it will load properly.

avatar image guavaman · Aug 19, 2015 at 06:56 PM 0
Share

@armirebrahimi_unity True, but this only works in the editor. You have to manually add the dylib to a build yourself or create a post build script to add it to the package.

avatar image amirebrahimi_unity · Aug 19, 2015 at 08:21 PM 1
Share

Yessir, you are correct.

5 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Magnus Wolffelt · Aug 04, 2010 at 02:27 PM

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!

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Magnus Wolffelt · Aug 04, 2010 at 06:09 PM 1
Share

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.

avatar image Magnus Wolffelt · Aug 05, 2010 at 09:38 AM 0
Share

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

avatar image Magnus Wolffelt · Aug 05, 2010 at 09:38 AM 0
Share

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

avatar image increpare · Apr 16, 2012 at 12:59 PM 0
Share

$$anonymous$$ajor 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. $$anonymous$$ay try to automate :)

avatar image guavaman · Jun 05, 2014 at 07:40 PM 0
Share

@$$anonymous$$agnus - The "sketchy" random behavior of plugins in OSX is a bug in Unity. It only re-imports your plugin when you choose Reimport All (or probably when you open and close Unity). This was pointed out by nay here: http://answers.unity3d.com/questions/548360/opengl-causing-dllnotfoundexception-on-osx.html

Show more comments
avatar image
2
Best Answer

Answer by jonas-echterhoff · Jul 29, 2010 at 09:22 AM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Magnus Wolffelt · Jul 29, 2010 at 10:10 AM 0
Share

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?

avatar image jonas-echterhoff ♦♦ · Jul 29, 2010 at 10:34 AM 0
Share

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.

avatar image Magnus Wolffelt · Jul 29, 2010 at 12:38 PM 0
Share

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.

avatar image
2

Answer by tedlin01 · Jun 02, 2013 at 09:11 PM

I wrote a tutorial for this at my blog. Hope it helps :)

http://www.tedlindstrom.se/how-to-link-dylibs-into-unity3d/

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image konsnos · Jun 27, 2018 at 10:28 AM 0
Share

Link is dead to me.

avatar image cecyliaw · Nov 17, 2020 at 07:17 PM 0
Share

Link doesn't work :/

avatar image
0

Answer by tristanjl · Oct 23, 2013 at 05:05 AM

Following up on Magnus Wolffelt's IOException issue, we had the same issue occurring and added a UnityEditor.Callbacks.PostProcessScene script that, on !EditorApplication.isPlayingOrWillChangePlaymode, moves the bundle outside of the plugins directory and a UnityEditor.Callbacks.PostProcessBuild that moves it back to that directory and copies it into the app. It works well enough for us, could be better though.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by hogwash · Jul 03, 2018 at 12:44 PM

Here's how you can convert a dylib to a bundle:

 lipo -create build-release/src/nvtt/libnvtt_x86.dylib build-release/src/nvtt/libnvtt_x86_64.dylib -output nvtt
 mkdir -p ../../../UnityProject/Assets/Scripts/Editor/TextureImport/nvtt.bundle/Contents/MacOS/
 cp nvtt ../../../UnityProject/Assets/Scripts/Editor/TextureImport/nvtt.bundle/Contents/MacOS/

Alternatively if you just want to ship 64-bit then skip the lipo step and copy the dylib (without extension) to the Contents/MacOS folder

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Plugins on OSX (OpenCV and EmguCV) 2 Answers

Mono and missing types using external library 2 Answers

Windows 8 - DLLNotFoundException. Windows 7 - No problems! 0 Answers

How to use (AVPro) plugin with JavaScript. 1 Answer

How to include dependent dylib for Mac plugin? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges