I'm creating bindings for Xamarin.Mac / MonoMac. I'd like to embed the dylib in the generated dll like it's done on Xamarin.iOS with the [LinkWith] attribute.
Is it possible to do that ? if so how ? Or should I load the dylib from the consuming application ? again in this case, how ?
I tried:
- dropping the dylib in the Native References folder (doesn't work)
- adding a [assembly: MonoMac.RequiredFramework] attribute (doesn't find the dylib)
This involves the following four steps: Build the native library. Prepare the Xamarin metadata, which enables Xamarin tooling to generate C# classes. Build a Xamarin Binding Library using the native library and metadata. Consume the Xamarin Binding Library in a Xamarin application. The following guide outlines these steps with additional details.
If you have the need to consume a C Dylib in your Xamarin.iOS application, there is a bit of extra setup that is required before calling the DllImport attribute.
When working with Xamarin.iOS or Xamarin.Mac, you might encounter cases where you want to consume a third-party Objective-C library. In those situations, you can use Xamarin Binding Projects to create a C# binding to the native Objective-C libraries.
The presence of keys sometimes is used as a boolean as well. The Xamarin.iOS binding generator provides support for developers to bind notifications. To do this, you set the [Notification] attribute on a property that has been also been tagged with a [Field] property (it can be public or private).
I managed to load the .dylib from the consuming application by doing the following:
.dylib to your project as Content
RequiredFrameworkAttribute: [assembly: MonoMac.RequiredFramework("mylib.dylib")]
AppDelegate constructor: public partial class AppDelegate : NSApplicationDelegate
{
public AppDelegate ()
{
Type t = typeof(ATypeFromTheAssembly);
MonoMac.ObjCRuntime.Runtime.RegisterAssembly (t.Assembly);
}
}
That still doesn't embed the .dylib in the bindings assembly, but it qualifies as progress
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With