- Home /
iOS C++ plugin that itself relies on framework
From my understanding, basic iOS C++ plugins are dead simple. Simply jot down working code in a .mm text file and shove that file into Assets/Plugin/iOS. Even simpler than making a windows .dll plugin.
But... what about an iOS plugin that itself makes calls to another framework like, say, OpenCV? How do you include that? The documentation beyond the most basic examples like the one I linked is sparse. Do I just dump opencv2.framework into Assets/Plugin/iOS and cross my fingers my own C++ code will know to talk to OpenCV's through some kind of magic? I am pretty sure there must be some additional steps, probably once the generated project's gotten to Xcode's side of things. What would these steps be?
Any help or link to a tutorial or documentation pertinent to my use case highly appreciated. Thanks!
User code in unity uses C# or UnityScript(very similar to javascript) to use a code from a c++ dll you will need use C# Interoperability to use the dll content.
See Interoperability (C# Program$$anonymous$$g Guide)
I know that. I successfully made what I needed for Editor / Windows and Android phones / tablets as a .dll and a .so respectively. $$anonymous$$y C++ .dll gives me a layer to interface with the few OpenCV for Windows methods I need while in the Editor, and my C++ .so gives me the same for Android.
Now I need to get the same functionality ported to iOS, which probably means dancing with Xcode to create my own static library (.a) to, again, interface between Unity and OpenCV. $$anonymous$$aking a straight iOS Unity plugin for something like adding two int or returning "hello world" is simple. $$anonymous$$aking a straight include of OpenCV for an iOS app without going through Unity at all is also simple. It's both ends, Unity > iOS <- OpenCV (or any other framework) that there doesn't seem to be any documentation about gluing together.
You can't create the methods in C# or UnityScript? Unity have packages specific for iOS and Android and you can use #if to check the plataform.
Answer by roypo · Nov 03, 2016 at 02:21 PM
In Xcode I made a static library (a .a file) implementing the header and source for my methods. That static library was linked to the OpenCV for iOS framework. I had to make sure to copy the framework's Headers and Resources subfolders and opencv2 file, all located in Versions\A, back to the root of the framework.
I could then place the static library and the OpenCV for iOS framework in my Unity iOS plugin folder, and use the library from Unity script as I would a .dll or .so through [DllImport ("__Internal")].