Take a look at my answer to this question: Setting up the path for the Native Library for DllImport for Mono for Mac
The binary launcher comes from monodevelop / main / build / MacOSX / monostub.m .
You can use either MyApp.app/Contents/Frameworks , or some other path, the important part is not to use the path names in your [DllImport] , but instead add <dllmap> with @executable_path to your app.config , as I explained a different answer to this.
There is also a link to a test application on github.
Detailed instructions
Choose the path inside MyApp.app to install your native DLL, for example Contents/SharedSupport/sqlite3.0.8.6.dylib .
Compute the relative path from the directory where the managed assembly is located on the native .dll and prepend @executable_path .
For example, if your managed assembly is located in Contents/MonoBundle/MyApp.exe , and the native dll is in Contents/SharedSupport/sqlite3.0.8.6.dylib , then this is @executable_path/../SharedSupport/sqlite3.0.8.6.dylib .
Change the installed library name to this relative path using install_name_tool .
Add a new MyApp.exe.config file to the project containing
<configuration> <dllmap dll="sqlite" target="@executable_path/../SharedSupport/sqlite3.0.8.6.dylib" /> </configuration>
Use the path that you calculated in step 2. for the target field. Right-click the file in MonoDevelop, select "Quick Properties" in the context menu and enable "Copy to Output Directory". This will copy the file to the Contents/MonoBundle , so it will be next to your MyApp.exe .
Use [DllImport ("sqlite")] to refer to this in your code.
When another library references it
When another library, such as Mono.Data.Sqlite.dll refers to it, it becomes a little more complicated.
Use the same steps as above, but you need to find out what name the other library in [DllImport] to refer to its own library and put it in <dllimport dll="..." /> . You can search for [DllImport] operators in the source code or run monodis in the assembly and search for pinvokeimpl , for example:
// method line 679 .method assembly static hidebysig pinvokeimpl ("sqlite3" as "sqlite3_create_function" cdecl ) default int32 sqlite3_create_function (native int db, unsigned int8[] strName, int32 nArgs, int32 nType, native int pvUser, class Mono.Data.Sqlite.SQLiteCallback func, class Mono.Data.Sqlite.SQLiteCallback fstep, class Mono.Data.Sqlite.SQLiteFinalCallback ffinal) cil managed preservesig { // Method begins at RVA 0x0 } // end of method UnsafeNativeMethods::sqlite3_create_function
So, Mono.Data.Sqlite.dll uses "sqlite3" to reference the native dll, so your MyApp.exe.config file will look like this:
<configuration> <dllmap dll="sqlite3" target="@executable_path/../SharedSupport/sqlite3.0.8.6.dylib" /> </configuration>
Martin baulig
source share