Search code examples
androidxamarinxamarin.androidandroid-ndktbb

Xamarin - attempt to load libtbb.so results in "libc.so" not found message in runtime


I'm developing app using Xamarin.Forms and currently testing it on Android phone (Android 6, armeabi-v7a). The target API is 21, my dev machine runs Windows. I'm also using several native libraries build by NDK, but for isolation, I created one small library which does nothing but return a number from a single exported function.

Now I need to link Intel TBB library to my native library, so I build one using ndk build tools and clone of TBB repository:

ndk-build target=android tbb tbb_os=windows arch=armeabi-v7a

This resulted into libtbb.so and libtbb_debug.so libraries, which I then added to my Xamarin Android project as AndroidNativeLibrary, additionally set <Abi>armeabi-v7a</Abi> and copying to destination directory, compiled and deployed to my phone.

Also I have some testing code in C# just to call native library (which works fine without linking TBB).

Here's the problem - after linking TBB (even without actually using anything from TBB library), code crashes when attempting to load native library with message:

DllImport error loading library 'libmyproject_experimental.so': 'dlopen failed: cannot find "libc.so" from verneed[0] in DT_NEEDED list for "/data/app/com.example.myapp.myproject-1/lib/arm/libtbb.so"'.

So I created a new project in my Xamarin project for TBB, added TBB sources, set correct flags, so the code builds correctly (I set the same flags as in ndk-build outputs) and added TBB project reference to my experimental library. This just moved the problem from TBB to my library:

DllImport error loading library 'libmyproject_experimental.so': 'dlopen failed: cannot find "libc.so" from verneed[0] in DT_NEEDED list for "/data/app/com.example.myapp.myproject-1/lib/arm/libmyproject_experimental.so"'.

I also changed STL to libc++_shared everywhere, enabled exceptions and RTTI and set c++1y as C++ standard. Also I'm using clang 5.0.

Any ideas how to solve this problem?

EDIT: when I build TBB in MSVS as static library, the message now says, that it could not find "libm.so" (which TBB also needs)


Solution

  • To answer my own question:

    I solved it by reconfiguring the project and by some of the following:

    • building TBB library as static
    • using static version of libc++
    • raising the minimum API level to 21 (used to be 19)

    However, I'm not sure what was the real problem.

    EDIT: the general idea to do static linkage came from here: https://software.intel.com/en-us/forums/intel-threading-building-blocks/topic/623425