Choose folder where DllImport looks for libs? (and the dependencies of a dependency)

RafaelBringelRafaelBringel Rafael BringelUSMember
edited September 29 in Xamarin.Mac

Hello, I'm porting a game I made with MonoGame to mac and I'm stuck on a DllImport problem, it usually works just fine, looking for any lib (dylib) on the same folder as the assembly, but I'm facing a serious problem now that a dependency of mine has it own dependencies.

The lib I'm trying to load, it loads just fine from the same folder as the executable, but it looks for the dependencies of that lib on the usr/local/lib.

What is the best way to face this problem?

For me, the optimal solution would be if every lib could be look at in a lib folder inside the game directory, but I'm not sure on how to do that.

Tagged:

Answers

  • ChrisHamonsChrisHamons Chris Hamons USXamarin Team Xamurai

    For any native library assembly load issue I suggest running with these environmental variables:

    MONO_LOG_LEVEL=debug MONO_LOG_MASK=dll

    as that will dump the steps mono is taking on your behalf (so you can understand the problem better).

    If you have a macOS bundle, you'll need to do something like:

    MONO_LOG_LEVEL=debug MONO_LOG_MASK=dll ./Foo.app/Contents/MacOS/Foo (With Foo replaced by your app name).

  • RafaelBringelRafaelBringel Rafael Bringel USMember
    Mono: DllImport attempting to load: 'libtheoraplay'.
    Mono: DllImport error loading library '/Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay': 'dlopen(/Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay, 9): image not found'.
    Mono: DllImport error loading library '/Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay.dylib': 'dlopen(/Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay.dylib, 9): Library not loaded: **/usr/local/lib/libogg.0.dylib**
      Referenced from: /Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay.dylib
      Reason: image not found'.
    Mono: DllImport error loading library '/Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay.so': 'dlopen(/Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay.so, 9): image not found'.
    Mono: DllImport error loading library '/Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay.bundle': 'dlopen(/Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay.bundle, 9): image not found'.
    Mono: DllImport error loading library '/Library/Frameworks/Mono.framework/lib/libtheoraplay': 'dlopen(/Library/Frameworks/Mono.framework/lib/libtheoraplay, 9): image not found'.
    Mono: DllImport error loading library '/Library/Frameworks/Mono.framework/lib/libtheoraplay.dylib': 'dlopen(/Library/Frameworks/Mono.framework/lib/libtheoraplay.dylib, 9): image not found'.
    Mono: DllImport error loading library '/Library/Frameworks/Mono.framework/lib/libtheoraplay.so': 'dlopen(/Library/Frameworks/Mono.framework/lib/libtheoraplay.so, 9): image not found'.
    Mono: DllImport error loading library '/Library/Frameworks/Mono.framework/lib/libtheoraplay.bundle': 'dlopen(/Library/Frameworks/Mono.framework/lib/libtheoraplay.bundle, 9): image not found'.
    Mono: DllImport error loading library '/Library/Frameworks/Mono.framework/Libraries/libtheoraplay': 'dlopen(/Library/Frameworks/Mono.framework/Libraries/libtheoraplay, 9): image not found'.
    Mono: DllImport error loading library '/Library/Frameworks/Mono.framework/Libraries/libtheoraplay.dylib': 'dlopen(/Library/Frameworks/Mono.framework/Libraries/libtheoraplay.dylib, 9): image not found'.
    Mono: DllImport error loading library '/Library/Frameworks/Mono.framework/Libraries/libtheoraplay.so': 'dlopen(/Library/Frameworks/Mono.framework/Libraries/libtheoraplay.so, 9): image not found'.
    Mono: DllImport error loading library '/Library/Frameworks/Mono.framework/Libraries/libtheoraplay.bundle': 'dlopen(/Library/Frameworks/Mono.framework/Libraries/libtheoraplay.bundle, 9): image not found'.
    Mono: DllImport error loading library 'libtheoraplay': 'dlopen(libtheoraplay, 9): image not found'.
    Mono: DllImport error loading library 'libtheoraplay.dylib': 'dlopen(libtheoraplay.dylib, 9): Library not loaded: **/usr/local/lib/libogg.0.dylib**
      Referenced from: /Users/dumativa/Desktop/LendaDoHeroi/trunk/DumaLegend/DumaLegend.DesktopGL/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/DumaLegend.DesktopGL2/bin/Debug/libtheoraplay.dylib
      Reason: image not found'.
    Mono: DllImport error loading library 'libtheoraplay.so': 'dlopen(libtheoraplay.so, 9): image not found'.
    Mono: DllImport error loading library 'libtheoraplay.bundle': 'dlopen(libtheoraplay.bundle, 9): image not found'.
    Mono: DllImport error loading library 'libtheoraplay': 'dlopen(libtheoraplay, 9): image not found'.
    Mono: DllImport unable to load library 'dlopen(libtheoraplay, 9): image not found'.
    

    Here is a really short version of the output, as I said, it successfully finds the libtheoraplay.dylib in the same folder where my game is, but it tries to load the libraries that this dylib needs somewhere else.

    It is possible to control where does it looks for that dependencies?

Sign In or Register to comment.