ObjCRuntime.Dlfcn.dlopen doesn't work

Hi,
Have a problem with return result from Dlfcn.dlopen (...).
Included the .framework library file in the Xamarin.iOS project, marked it as Embeded Library.
Also, the library file is included in the .app/.framework - it is located there physically and on the iOS device.

In the code, I check that the library file is on the path and I get value of the library file size.
Library file exist and have full size in bytes.
But set path to the library in dlopen, I do not get the return result, nor do I get any errors.

You can find sample code in the attachments.

What am I doing wrong and how do I use dlopen for *.framework*.so and other dynamic libraries?

Answers

  • RolfBjarneKvingeRolfBjarneKvinge USXamarin Team Xamurai
    edited October 29

    The problem is that the framework needs to be signed, and in the Frameworks subdirectory of the .app.

    If you add the framework like a native reference in the csproj, it will be automatically added to the Frameworks subdirectory and then signed during the build. The csproj should look something like this (depends a bit exactly where the av337.framework is in your project directory):

    <ItemGroup>
      <NativeReference Include="$(ProjectDir)\av337.framework">
        <Kind>Framework</Kind>
        <SmartLink>False</SmartLink>
      </NativeReference>
    </ItemGroup>
    

    and then you'll have to change these lines:

    var ln = @"av337.framework/av337";
    var documentsPath = NSBundle.MainBundle.BundlePath;
    var filePath = System.IO.Path.Combine(documentsPath, "Frameworks", ln);
    
  • anonimysanonimys Member

    @RolfBjarneKvinge said:
    The problem is that the framework needs to be signed, and in the Frameworks subdirectory of the .app.

    If you add the framework like a native reference in the csproj, it will be automatically added to the Frameworks subdirectory and then signed during the build. The csproj should look something like this (depends a bit exactly where the av337.framework is in your project directory):

    <ItemGroup>
      <NativeReference Include="$(ProjectDir)\av337.framework">
        <Kind>Framework</Kind>
        <SmartLink>False</SmartLink>
      </NativeReference>
    </ItemGroup>
    

    and then you'll have to change these lines:

    var ln = @"av337.framework/av337";
    var documentsPath = NSBundle.MainBundle.BundlePath;
    var filePath = System.IO.Path.Combine(documentsPath, "Frameworks", ln);
    

    Doesn't help, result of dlopen is 0
    IntPtr result = ObjCRuntime.Dlfcn.dlopen(filePath, 0); // result = 0x0

  • VolodymyrSavchenkoVolodymyrSavchenko UAMember ✭✭✭

    I have the same problem. Is there any solution? It's URGENT!

  • RolfBjarneKvingeRolfBjarneKvinge USXamarin Team Xamurai

    @anonimys: could you post a verbose build log (make sure you clean your solution first)?

  • CClaudiu_MSFTCClaudiu_MSFT USMember ✭✭

    @RolfBjarneKvinge I can confirm that your solution works and so @anonimys (I've discussed with him via our internal case)
    @VolodymyrSavchenko do you still have the issue?

Sign In or Register to comment.