Load native libraries in Xamarin Mac

jona1993jona1993 Member ✭✭
edited January 31 in Xamarin.Mac

Hi,

I have an issue for load 3 native libraries.

When I build my project, I have 3 warnings:

Warning MM2006: Native library 'libopusfm' was referenced but could not be found. (MM2006)

Warning MM2006: Native library 'libvpxfm' was referenced but could not be found. (MM2006)

Warning MM2006: Native library 'libyuvfm' was referenced but could not be found. (MM2006)

When I launch my project via Visual Studio, my app crash. However when I launch my app via these command lines:

$ DYLD_LIBRARY_PATH=/My/Project/Path/libs/native
$ /My/Project/Path/App.app/Contents/MacOS/App

It works.

Have you an idea why I can't load that with Visual studio?

In my csproj file:

I tested with
Variable: DYLD_LIBRARY_PATH
Value: /My/Project/Path/libs/native
In my project settings and It doesn't work. (And It's not the best idea..)

Thank you in advance.

Posts

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    So, depending on your settings, mmp might/should use install_name_path to set them all loadable from the BundleDirectory:

    https://github.com/xamarin/xamarin-macios/blob/master/tools/mmp/driver.cs#L1705

    Could you attach a full build log (gist or pastebin somewhere) and/or a project?

  • jona1993jona1993 Member ✭✭

    Logs in French, sorry.. ;)

    pastebin.com/ZSvsvScq

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Instead of running with -q (quiet):

    /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/mmp @/Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/obj/Debug/response-file.rsp -q
     -q
     -q
     -q
    

    Can you add some -v for verbose?

  • jona1993jona1993 Member ✭✭

    With some -v: ;)

    pastebin.com/zjLXkpde

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
        Copying file from '/Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/libs/native/libvpxfm.dylib' to '/Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/bin/Debug/XamarinMacIceLink3.app/Contents/Resources/libvpxfm.dylib'
        Copying file from '/Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/libs/native/libyuvfm.dylib' to '/Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/bin/Debug/XamarinMacIceLink3.app/Contents/Resources/libyuvfm.dylib'
        Copying file from '/Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/libs/native/libopusfm.dylib' to '/Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/bin/Debug/XamarinMacIceLink3.app/Contents/Resources/libopusfm.dylib'
    
        xcrun -sdk macosx install_name_tool -id @executable_path/../MonoBundle/libopusfm.dylib /Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/bin/Debug/XamarinMacIceLink3.app/Contents/MonoBundle/libopusfm.dylib
        Native library 'libvpxfm.dylib' copied to application bundle.
        xcrun -sdk macosx install_name_tool -id @executable_path/../MonoBundle/libvpxfm.dylib /Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/bin/Debug/XamarinMacIceLink3.app/Contents/MonoBundle/libvpxfm.dylib
        Native library 'libyuvfm.dylib' copied to application bundle.
        xcrun -sdk macosx install_name_tool -id @executable_path/../MonoBundle/libyuvfm.dylib /Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/bin/Debug/XamarinMacIceLink3.app/Contents/MonoBundle/libyuvfm.dylib
    

    It looks like two copies of your dylib is getting copied in? Are you doing the first one by hand (via an item in your project)?

    I suspect the first copy is the one crashing (as it isn't fixed up). Consider removing that, let mmp fix up a copy, and post a crash report if that doesn't help.

  • jona1993jona1993 Member ✭✭

    I deleted the Debug folder, I rebuilt my solution and same issue..

    % ls -al /Users/jona1993/Desktop/XamarinMacIceLink3/XamarinMacIceLink3/bin/Debug/XamarinMacIceLink3.app/Contents/Resources

    drwxr-xr-x 10 jona1993 staff 320 4 fév 08:08 .
    drwxr-xr-x 7 jona1993 staff 224 4 fév 08:05 ..
    -rw-r--r-- 1 jona1993 staff 31968 3 fév 16:40 AppIcon.icns
    -rw-r--r-- 1 jona1993 staff 258344 3 fév 16:40 Assets.car
    drwxr-xr-x 9 jona1993 staff 288 4 fév 08:05 Main.storyboardc
    [email protected] 1 jona1993 staff 470444 23 jan 01:07 libopusfm.dylib
    [email protected] 1 jona1993 staff 1895592 23 jan 01:07 libvpxfm.dylib
    [email protected] 1 jona1993 staff 327852 23 jan 01:07 libyuvfm.dylib
    -rw-r--r-- 1 jona1993 staff 500001 4 fév 08:08 mono_crash.mem.34479.1.blob
    -rw-r--r-- 1 jona1993 staff 259 4 fév 08:05 runtime-options.plist

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    edited February 4

    I'm suggesting in your csproj you have libvpxfm.dylib listed twice, once as a native reference and one as a copy into bundle.

    Since you haven't posted an example project, we have to play guess and check here.

  • jona1993jona1993 Member ✭✭

    I deleted each native references, same issue.

    I will send the project, It's better ;)

    https://app.box.com/s/i9nx1d3hqj67y6r2dduap8x2d392vrsb

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Strangely it doesn't crash for me on launch. However, you really should use a native reference for libraries like this.

    I swapped it: https://gist.github.com/chamons/d1d425ba5acbb8d23dac267097d35b83

    Still no crash with that. What version of Xamarin.Mac are you running?

  • jona1993jona1993 Member ✭✭
    edited February 6

    It doesn't crash at startup. It crash when I would start the video. (When I insert my username + session id => Connect).
    These libraries are used for codecs. However, you must have some servers to works..

    But these 3 warnings are strange. If I can't load codecs, I don't can have the video.

    Xamarin mac version: 6.14.1.23

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Does it crash with the project change I posted above?

  • jona1993jona1993 Member ✭✭

    Yes, it crash.. :/

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Can you post a crash log and/or steps to reproduce. It sounds like your dylibs are either in the right location relative to each other or aren't being install_name_tooled

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
        0x7fff5c6985a7 - /System/Library/PrivateFrameworks/TCC.framework/Versions/A/TCC : TCCAccessRequestIndirect
        0x7fff5c696545 - /System/Library/PrivateFrameworks/TCC.framework/Versions/A/TCC : __TCCAccessCheckAuditToken_block_invoke
        0x7fff5c696a6c - /System/Library/PrivateFrameworks/TCC.framework/Versions/A/TCC : __tccd_send_message_block_invoke
    

    This is the important part. TCC is a private framework from Apple, which kills your application when it is signed / hardened and fails to meet some requirement.

    Almost always, it is because you've not opted into some thing (like network, or camera access) in your entitlement file. Check your entitlements and you'll likely find your culprit.

  • jona1993jona1993 Member ✭✭

    It work now ;)

    I added in the info.plist:

    <key>NSCameraUsageDescription</key>
    <string>Need to access your camera to capture a picture and record a video.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>Need to access your microphone to record a video.</string>
    

    Thank you very much ! :)

    Have a nice day.

Sign In or Register to comment.