java.lang.unsatisfiedLinkError lib not found :(未能链接 mylib.so)
Posted
技术标签:
【中文标题】java.lang.unsatisfiedLinkError lib not found :(未能链接 mylib.so)【英文标题】:java.lang.unsatisfiedLinkError lib not found :(failed to link mylib.so) 【发布时间】:2013-03-10 05:20:21 【问题描述】:我已经使用 android ndk 独立工具链 成功地将 c++ 库 交叉编译到了 android 平台。 我已经使用 jni dolder 和 Android.mk 文件在 Eclipse 中创建了一个新的 android 应用程序项目,当我执行 ndk-build 时,构建进展顺利,并将 mylib.so 添加到 libs/armeabi 文件夹 问题是当我做一个 System.loadLibrary("mylibname"); 我在 logcat 中收到以下错误: 无法 dlopen(/data/data/com.oussama.firsttry/lib/libdash.so):无法加载库:link_image [1995]:无法链接 libdash.so 这会导致 java.lang.UnsatisfiedLinkError: my lib not found**。
我的 lib 必须有一个库,而模拟器无法加载它,所以我做了一个 readelf -d mylib.so,结果如下:
偏移 0x1617c4 处的动态部分包含 26 个条目:
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
这是我的 Android.mk 文件:
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)
我现在真的被卡住了,我无法弄清楚丢失的库是什么
当我执行 ndk-build V=1 -B 时,我得到以下结果:
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: 循环 obj/local/armeabi/libm.so obj/local/armeabi/libdl.so 预建:libm.so /home/oussama064/Android/workspace/FirstTry/libs/armeabi/libc.so 安装 -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 预建: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 预建:libcurl.a obj/local/armeabi/libcurl.a 预建:libdash.so
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
如果有人可以帮助我,我将不胜感激。
【问题讨论】:
好吧,你正在尝试加载mylib.so
,但你得到的只是libdash.so
。如果这不是问题,您已经编辑了错误消息,所以请复制并粘贴正确的错误文本。
您应该在问题中给出正确的描述,您要加载哪个库?无论如何,我的两分钱都在你应该使用 System.loadLibrary("dash")
我已经完成了 System.loadLibrary("dash");就像我在错误消息中看到的那样,android 实际上在 libs/armeabi/libdash.so 下找到了 lib
【参考方案1】:
你应该使用系统版本的libm、libc和libdl共享库,
LOCAL_LDLIBS := -lm -ldl
如果不能,请静态链接它们。
【讨论】:
以上是关于java.lang.unsatisfiedLinkError lib not found :(未能链接 mylib.so)的主要内容,如果未能解决你的问题,请参考以下文章