1

Am using

Xamarin Studio - 6.1.2 (build 44) Xamarin.iOS Version: 10.2.1.5.

I am trying to binding C "thirdparty.dylib" in my Xamarin.iOS Application. it's a Dynamic library I have followed https://developer.xamarin.com/guides/ios/advanced_topics/native_interop/

static void Main(string[] args)
    {           
        string fileName = "liba.dylib"; 
        string docfolder =   Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        string dbpath = Path.Combine(docfolder, fileName);

        var a = ObjCRuntime.Dlfcn.dlopen(dbpath, 0);
        if (a == IntPtr.Zero)
        {
            Console.WriteLine("[FAIL] TestDlopenSystem: Could not dlopen liba.dylib");
        }

        UIApplication.Main(args, null, "AppDelegate");
    }

I have put "liba.dylib" in iOS device internal storage by iTunes but when I try to "ObjCRuntime.Dlfcn.dlopen" "intptr" always return zero

[DllImport("liba.dylib", EntryPoint="foo")]
public static extern double foo();

when I try to use Dllimport its always return DllNotFoundException.

Dylib is not load into memory.

  • Possible duplicate of [Can you build dynamic libraries for iOS and load them at runtime?](http://stackoverflow.com/questions/4733847/can-you-build-dynamic-libraries-for-ios-and-load-them-at-runtime) – Jon Douglas Nov 29 '16 at 16:54
  • Here's what we tried, 1) We have added dylib as bundle resource in our project. 2) Using install_name_tool we set dylib path to @rpath/liba.dylib 3) Added the [DllImport ("@rpath/liba.dylib")] into code 4) Then we have added additional mtouch arguments as -gcc_flags "-L/Users/datacomp/projects/Dylibtest/Dylibtest/ -la"   However we got the error ex {System.DllNotFoundException: @rpath/liba.dylib at (wrapper managed-to-native) – neil patankar Dec 01 '16 at 05:42

0 Answers0