java.lang.unsatisfiedLinkError lib not found :(failed to link mylib.so)

0

i've successfully cross compiled a c++ library to the android plateform using the android ndk standalone toolchain. i've created a new android application project into Eclipse with a jni dolder and Android.mk file and when i do an ndk-build the building goes well and it adds mylib.so to libs/armeabi folder The problem is when i do a System.loadLibrary("mylibname"); i get the following error in the logcat: Unable to dlopen(/data/data/com.oussama.firsttry/lib/libdash.so): Cannot load library: link_image[1995]: failed to link libdash.so that cause a java.lang.UnsatisfiedLinkError: my lib not found**.

There must be a library that my lib depends on and the emulator can't load it so i've done a readelf -d mylib.so and here is the result:

Dynamic section at offset 0x1617c4 contains 26 entries:

 Tag        Type                         Name/Value
0x00000001 (NEEDED)                     Shared library: [libm.so]
0x00000001 (NEEDED)                     Shared library: [libc.so]
0x00000001 (NEEDED)                     Shared library: [libdl.so]
0x0000000e (SONAME)                     Library soname: [libdash.so]
0x00000010 (SYMBOLIC)                   0x0
0x0000000f (RPATH)                      Library rpath:      [/home/oussama064/libdash/libdash/../../neededLibs]
0x00000019 (INIT_ARRAY)                 0x157268
0x0000001b (INIT_ARRAYSZ)               172 (bytes)
0x0000001a (FINI_ARRAY)                 0x157314
0x0000001c (FINI_ARRAYSZ)               8 (bytes)
0x00000004 (HASH)                       0xf4
0x00000005 (STRTAB)                     0x10f58
0x00000006 (SYMTAB)                     0x50b8
0x0000000a (STRSZ)                      134112 (bytes)
0x0000000b (SYMENT)                     16 (bytes)
0x00000003 (PLTGOT)                     0x1618b4
0x00000002 (PLTRELSZ)                   1096 (bytes)
0x00000014 (PLTREL)                     REL
0x00000017 (JMPREL)                     0x40dd8
0x00000011 (REL)                        0x31b38
0x00000012 (RELSZ)                      62112 (bytes)
0x00000013 (RELENT)                     8 (bytes)
0x00000018 (BIND_NOW)                   
0x6ffffffb (FLAGS_1)                    Flags: NOW
0x6ffffffa (RELCOUNT)                   7738
0x00000000 (NULL)                       0x0

Here is my Android.mk file:

 LOCAL_PATH := $(call my-dir)

 include $(CLEAR_VARS) LOCAL_MODULE    := libcurl  LOCAL_SRC_FILES :=
 ../../../../neededLibs/libcurl.a

 include $(PREBUILT_STATIC_LIBRARY)

 include $(CLEAR_VARS) LOCAL_MODULE    := libxml  LOCAL_SRC_FILES :=
 ../../../../neededLibs/libxml2.a

 include $(PREBUILT_STATIC_LIBRARY)

 include $(CLEAR_VARS) LOCAL_MODULE    := libz  LOCAL_SRC_FILES :=
 ../../../../neededLibs/libz.a

 include $(PREBUILT_STATIC_LIBRARY)

 include $(CLEAR_VARS) LOCAL_MODULE    := m  LOCAL_SRC_FILES :=
 libm.so include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS)
 LOCAL_MODULE    := dl  LOCAL_SRC_FILES := libdl.so

 include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE
 := c  LOCAL_SRC_FILES := libc.so

 include $(PREBUILT_SHARED_LIBRARY)

 include $(CLEAR_VARS)

 LOCAL_MODULE := d LOCAL_SRC_FILES := libdash.so
 LOCAL_SHARED_LIBRARIES := c m dl 

 LOCAL_STATIC_LIBRARIES := libz libxml libcurl  include
 $(PREBUILT_SHARED_LIBRARY)

i'am really stuck now and i can't figure out what is the missing library

When i do an ndk-build V=1 -B i get the following result:

rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/lib*.so   

/home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/lib*.so /home/oussama064/Android/workspace/FirstTry/libs/mips/lib*.so /home/oussama064/Android/workspace/FirstTry/libs/x86/lib*.so rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/gdbserver /home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/gdbserver /home/oussama064/Android/workspace/FirstTry/libs/mips/gdbserver /home/oussama064/Android/workspace/FirstTry/libs/x86/gdbserver rm -f /home/oussama064/Android/workspace/FirstTry/libs/armeabi/gdb.setup /home/oussama064/Android/workspace/FirstTry/libs/armeabi-v7a/gdb.setup /home/oussama064/Android/workspace/FirstTry/libs/mips/gdb.setup /home/oussama064/Android/workspace/FirstTry/libs/x86/gdb.setup make: Circular obj/local/armeabi/libm.so <- obj/local/armeabi/libm.so dependency dropped. make: Circular obj/local/armeabi/libm.so <- obj/local/armeabi/libc.so dependency dropped. make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libm.so dependency dropped. make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libc.so dependency dropped. make: Circular obj/local/armeabi/libdl.so <- obj/local/armeabi/libdl.so dependency dropped. Prebuilt : libdl.so <= /home/oussama064/Android/workspace/FirstTry/jni/ cp -f /home/oussama064/Android/workspace/FirstTry/jni/libdl.so
obj/local/armeabi/libdl.so Prebuilt : libm.so <= /home/oussama064/Android/workspace/FirstTry/jni/ cp -f /home/oussama064/Android/workspace/FirstTry/jni/libm.so obj/local/armeabi/libm.so make: Circular obj/local/armeabi/libc.so <- obj/local/armeabi/libc.so dependency dropped. Prebuilt : libc.so <= /home/oussama064/Android/workspace/FirstTry/jni/ cp -f /home/oussama064/Android/workspace/FirstTry/jni/libc.so obj/local/armeabi/libc.so Install : libc.so => /home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so install -p ./obj/local/armeabi/libc.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so /home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi- 4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so Prebuilt : libxml2.a <=
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/ cp -f
/home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/libxml2.a obj/local/armeabi/libxml2.a Prebuilt : libcurl.a <= /home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/ cp -f /home/oussama064/Android/workspace/FirstTry/jni/../../../../neededLibs/libcurl.a
obj/local/armeabi/libcurl.a Prebuilt : libdash.so <= /home/oussama064/Android/workspace/FirstTry/jni/

cp -f /home/oussama064/Android/workspace/FirstTry/jni/libdash.so      
obj/local/armeabi/libdash.so
Install        : libdash.so =>   
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
install -p ./obj/local/armeabi/libdash.so    
 /home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded  
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdash.so
Install        : libdl.so => 
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so

install -p ./obj/local/armeabi/libdl.so 

/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so /home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded

/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libdl.so
Install        : libm.so =>   
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
install -p ./obj/local/armeabi/libm.so
/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so
/home/oussama064/NDK/android-ndk-r8d/toolchains/arm-linux-androideabi-     

4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-strip --strip-unneeded    

/home/oussama064/Android/workspace/FirstTry/libs/armeabi/libm.so

I would be thankfull if any one can help me.

android
c++
android-ndk
cross-compiling
asked on Stack Overflow Mar 20, 2013 by Hadj Ali Oussama • edited Mar 21, 2013 by Hadj Ali Oussama

1 Answer

0

You should use the system versions of libm, libc and libdl shared libraries,

LOCAL_LDLIBS := -lm -ldl 

If you can't, link them statically.

answered on Stack Overflow Apr 10, 2016 by Alex Cohn

User contributions licensed under CC BY-SA 3.0