Android NDK: dlopen failed

前端 未结 1 2019
鱼传尺愫
鱼传尺愫 2020-11-28 15:35

I have a weird error where it says:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot find \"./obj/local/armeabi-v7a/libsharedlibrary.so\" from verneed[         


        
相关标签:
1条回答
  • 2020-11-28 15:56

    libsharedlibrary.so is missing its SONAME entry. You probably currently see something like the following:

    $ readelf -dW libnative.so | grep NEEDED | grep libsharedlibrary
     0x0000000000000001 (NEEDED)             Shared library: [./obj/local/armeabi-v7a/libsharedlibrary.so]
    

    Note that if you don't have readelf on your system it is provided in the NDK as $NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-readelf (adjust the path as necessary for your OS). Note that the architecture here doesn't actually matter. readelf is a multi-arch tool. Any toolchain's readelf will work fine.

    What you should see if libsharedlibrary.so was built with SONAME is:

    $ readelf -dW libnative.so | grep NEEDED | grep libsharedlibrary
     0x0000000000000001 (NEEDED)             Shared library: [libsharedlibrary.so]
    

    You should see the following on libsharedlibrary.so:

    $ readelf -dW libsharedlibrary.so | grep SONAME
     0x000000000000000e (SONAME)             Library soname: [libsharedlibrary.so]
    

    The problem is that libsharedlibrary.so was not built with the -Wl,-soname,libsharedlibrary.so ldflag. ndk-build and CMake will do that for you, but if you're using a standalone toolchain or a custom build system then you need to provide it yourself.

    0 讨论(0)
提交回复
热议问题