- Home /
Native Plugin library depends on another library: DllNotFoundException
My setup is a little bit tricky.
I have a class included in a library written in C++ for linux (.so). Let's name that library "MainLibrary". It is detected in Unity in Windows as a native plugin the same way a .dll file is detected. My target platform is linux.
I'd create an instance of the class inside MainLibrary, but sadly we can't use classes inside a c++ library from c# . We can only import the static functions via
[DllImport("libraryName")]
public static extern void Function();
So the popular way to create an instance of the object inside MainLibrary is to create a wrapper library called "WrapperLibrary" over "MainLibrary" without a class.
WrapperLibrary contains the same methods as MainLibrary, but also contains a CreateInstance() method and a DestroyInstance() method. The first creates an instance of the "MainLibrary" class, and returns it , the second destroys the instance you pass. So you have to keep that class instance (in c# it will be an IntPtr, a generic address), and pass it to every method. So it doesn't have to manage the instance at all.
Given this setup, it is obvious that WrapperLibrary is the one accessed from C# using [DllImport("WrapperLibrary")], and it depends on MainLibrary.so.
So I include both .so files and the .h header file from MainLibrary , those three files together, into the Unity project. In the plugin inspector I activate all for Runtime on linux. Generate a build for linux, and execute it in linux. The two .so files are included inside a "Plugins" library in the build.
Well, seems like Unity depends only on the MainLibrary but the wrapper is not detected at all. A DllNotFoundException is thrown for the Wrapper.
It worked with just MainLibrary. The moment I created this wrapper class it was all broken. I didn't change anything except the import of the files. Both libraries are compiling correctly, Wrapper has a dependency to Main and it works perfectly.
Any ideas? Thanks!
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Net Standard core 2.0 library states .NET 4.x 2 Answers
GetNativeTexturePtr is not working in iOS plugin 1 Answer
Linux build is putting libNative.so in wrong place 1 Answer
Multiple Cars not working 1 Answer