Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed dylib in Xamarin.Mac binding dll

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)

like image 313
Stephane Delcroix Avatar asked Mar 07 '13 12:03

Stephane Delcroix


People also ask

How do I create a binding library in Xamarin?

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.

Can I consume a C dylib in my Xamarin iOS application?

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.

How do I use third-party Objective-C libraries with Xamarin?

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.

How do I bind a Boolean to a Xamarin iOS field?

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).


1 Answers

I managed to load the .dylib from the consuming application by doing the following:

  • Add the .dylib to your project as Content
  • add the RequiredFrameworkAttribute:
    [assembly: MonoMac.RequiredFramework("mylib.dylib")]
  • register the assembly from the 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

like image 194
Stephane Delcroix Avatar answered Sep 23 '22 19:09

Stephane Delcroix