Forum Xamarin.iOS

dylib dynamic loading issue

MartzMartz USMember ✭✭


I'm currently trying to load a C dylib at runtime in my iOS app and failing spectacularly. Any help appreciated.

Running in an iOS 11 simulator (so x86_64 I'd assume).

So, this

<NativeReference Include="libvlc.dylib">

does not put it in the .app bundle and outputs the following warning:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(786,3): warning : Dynamic native references are not supported: 'libvlc.dylib'.

It isn't? I'm missing something here...?

Anyway, including the dylib with Content Include or BundleResource successfully includes it in the final .app bundle (even if that's not The Right Way).
P/Invoking into it throws a DllNotFoundException.
Adding <MtouchExtraArgs>--setenv:MONO_LOG_LEVEL=debug</MtouchExtraArgs> to get more info prints out a bunch of logs including

info: DllImport error loading library 'libvlc.dylib': 'dlopen(libvlc.dylib, 9): no suitable image found.  Did find:
    libvlc.dylib: no matching architecture in universal wrapper'.


$ file libvlc.dylib
libvlc.dylib: Mach-O universal binary with 5 architectures: [arm_v7:current ar archive] [arm64]
libvlc.dylib (for architecture armv7):    current ar archive
libvlc.dylib (for architecture armv7s):    current ar archive
libvlc.dylib (for architecture i386):    current ar archive
libvlc.dylib (for architecture x86_64):    current ar archive
libvlc.dylib (for architecture arm64):    current ar archive

Calling ObjCRuntime.Dlfcn.dlopen with the correct path, in Main.cs, before UIApplication.Main(args, null, "AppDelegate");, always returns null.

FYI, this worked at some point a couple days ago but now I'm unsure why. Maybe planets were aligned and my bin folder had just the right pieces of artifacts hanging out together, in the right order :smile:
FYI bis, I did managed to link with the .a version of the lib before, using

<MtouchExtraArgs>-cxx -gcc_flags "-L${ProjectDir} -lbz2 -lvlc -framework AudioToolbox -framework VideoToolbox -framework AVFoundation -framework CoreMedia -framework CoreText -framework CoreImage -framework Security ${ProjectDir}/libvlc.a"</MtouchExtraArgs>

I'm on Stable (VS 7.4.1).

Any help/insights highly appreciated.

Sign In or Register to comment.