Forum Xamarin.Mac

How can I use native dylib in my project?

I was looking for any information, but most of it is about iOS.
I have third-party dylib libraries. How can I include them in my solution? What is dylib binding project? Should I use it?

Tagged:

Best Answer

  • VolodymyrSavchenkoVolodymyrSavchenko UAMember ✭✭✭
    Accepted Answer

    @ChrisHamons said:

    I don't know how, but it was enought to copy my .dylib files to my macOS project and then add native references to those files.
    That's all!

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    https://docs.microsoft.com/en-us/xamarin/mac/platform/binding

    But yes, almost all of the documentation is iOS flavored. The process is pretty much identical.

    You can either use binding projects to bind obj-c libraries and native libraries and "raw" p/invokes to call C APIs.

  • VolodymyrSavchenkoVolodymyrSavchenko UAMember ✭✭✭
    edited September 17

    @ChrisHamons said:
    https://docs.microsoft.com/en-us/xamarin/mac/platform/binding

    But yes, almost all of the documentation is iOS flavored. The process is pretty much identical.

    You can either use binding projects to bind obj-c libraries and native libraries and "raw" p/invokes to call C APIs.

    Can you tell me please, what are the key differences in using binding project on iOS and macOS?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Off the top of my head:

    • The input dylib/frameworks have different architecture slices. iOS almost always has multiple to cover simulator and device. macOS are often but not always x86_64 these days.
    • The process of creating a C# definition to map to the objc is the same, except the base types (UIKit vs AppKit classes)
    • The output (a managed dll with the lib embedded by default) is the same.
    • Use (include a reference in your app project) should be the same.
  • VolodymyrSavchenkoVolodymyrSavchenko UAMember ✭✭✭
    Accepted Answer

    @ChrisHamons said:

    I don't know how, but it was enought to copy my .dylib files to my macOS project and then add native references to those files.
    That's all!

Sign In or Register to comment.