Android NDK 与共享 .so 链接
Android NDK linking with shared .so
我有一个测试应用程序,我正尝试 link 使用 ibicuuc 和 libicui18n。 (这是更大项目的第一步)。
我将这些作为预建库包含在我的项目中
LOCAL_SHARED_LIBRARIES := libicuuc libicui18n
从 git 存储库按原样编译:
https://android.googlesource.com/platform/external/icu4c/
这是干净的构建日志:
$ ndk-build
[armeabi-v7a] Prebuilt : libicui18n.so <= /usr/local/opt/android/libs/libs/armeabi-v7a/
[armeabi-v7a] Install : libicui18n.so => libs/armeabi-v7a/libicui18n.so
[armeabi-v7a] Prebuilt : libicuuc.so <= /usr/local/opt/android/libs/libs/armeabi-v7a/
[armeabi-v7a] Install : libicuuc.so => libs/armeabi-v7a/libicuuc.so
[armeabi-v7a] Compile++ thumb: main <= main.cc
[armeabi-v7a] SharedLibrary : libmain.so
[armeabi-v7a] Install : libmain.so => libs/armeabi-v7a/libmain.so
这看起来不错,作为测试如果我错过了 LOCAL_SHARED_LIBRARIES 中的库,构建会按预期失败
/usr/local/opt/android/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/main/main.o: in function test_icu():jni/src/main.cc:71: error: undefined reference to 'unum_countAvailable_53'
collect2: ld returned 1 exit status
一切都很好,但是当应用程序是 运行 时,找不到符号:
D/dalvikvm( 7846): Trying to load lib /data/app-lib/net.alphawave.test.nativelibs-1/libmain.so 0x41e646a0
E/dalvikvm( 7846): dlopen("/data/app-lib/com.example.test.nativelibs-1/libmain.so") failed: dlopen failed: cannot locate symbol "unum_countAvailable_53" referenced by "libmain.so"...
W/dalvikvm( 7846): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/test/nativelibs/NativeLibs;
W/dalvikvm( 7846): Class init failed in newInstance call (Lcom/example/test/nativelibs/NativeLibs;)
D/AndroidRuntime( 7846): Shutting down VM
W/dalvikvm( 7846): threadid=1: thread exiting with uncaught exception (group=0x41591ba8)
E/AndroidRuntime( 7846): FATAL EXCEPTION: main
E/AndroidRuntime( 7846): Process: com.example.test.nativelibs, PID: 7846
E/AndroidRuntime( 7846): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "unum_countAvailable_53" referenced by "libmain.so"...
我试过预加载这些库,但这似乎没有帮助:
static {
System.loadLibrary("icuuc");
System.loadLibrary("icui18n");
System.loadLibrary("main");
}
这导致:
D/dalvikvm( 8277): Trying to load lib /data/app-lib/com.example.test.nativelibs-1/libicuuc.so 0x41e6d310
D/dalvikvm( 8277): Added shared lib /data/app-lib/com.example.test.nativelibs-1/libicuuc.so 0x41e6d310
D/dalvikvm( 8277): No JNI_OnLoad found in /data/app-lib/com.example.test.nativelibs-1/libicuuc.so 0x41e6d310, skipping init
D/dalvikvm( 8277): Trying to load lib /data/app-lib/com.example.test.nativelibs-1/libicui18n.so 0x41e6d310
D/dalvikvm( 8277): Added shared lib /data/app-lib/com.example.test.nativelibs-1/libicui18n.so 0x41e6d310
D/dalvikvm( 8277): No JNI_OnLoad found in /data/app-lib/com.example.test.nativelibs-1/libicui18n.so 0x41e6d310, skipping init
D/dalvikvm( 8277): Trying to load lib /data/app-lib/com.example.test.nativelibs-1/libmain.so 0x41e6d310
E/dalvikvm( 8277): dlopen("/data/app-lib/com.example.test.nativelibs-1/libmain.so") failed: dlopen failed: cannot locate symbol "unum_countAvailable_53" referenced by "libmain.so"...
符号存在于 icui18n 库中:
$ arm-linux-gnueabi-readelf -aW libicui18n.so | grep unum_countAvailable
3700: 000ee8a9 4 FUNC GLOBAL DEFAULT 7 unum_countAvailable_53
我错过了什么?还是 icu* 构建需要一些 mod?
谢谢,
链接库(53 版)和 /system 库(51 版)不匹配,运行-time 链接器正在使用后者。
我问了修改过的问题!
我有一个测试应用程序,我正尝试 link 使用 ibicuuc 和 libicui18n。 (这是更大项目的第一步)。
我将这些作为预建库包含在我的项目中
LOCAL_SHARED_LIBRARIES := libicuuc libicui18n
从 git 存储库按原样编译:
https://android.googlesource.com/platform/external/icu4c/
这是干净的构建日志:
$ ndk-build
[armeabi-v7a] Prebuilt : libicui18n.so <= /usr/local/opt/android/libs/libs/armeabi-v7a/
[armeabi-v7a] Install : libicui18n.so => libs/armeabi-v7a/libicui18n.so
[armeabi-v7a] Prebuilt : libicuuc.so <= /usr/local/opt/android/libs/libs/armeabi-v7a/
[armeabi-v7a] Install : libicuuc.so => libs/armeabi-v7a/libicuuc.so
[armeabi-v7a] Compile++ thumb: main <= main.cc
[armeabi-v7a] SharedLibrary : libmain.so
[armeabi-v7a] Install : libmain.so => libs/armeabi-v7a/libmain.so
这看起来不错,作为测试如果我错过了 LOCAL_SHARED_LIBRARIES 中的库,构建会按预期失败
/usr/local/opt/android/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/main/main.o: in function test_icu():jni/src/main.cc:71: error: undefined reference to 'unum_countAvailable_53'
collect2: ld returned 1 exit status
一切都很好,但是当应用程序是 运行 时,找不到符号:
D/dalvikvm( 7846): Trying to load lib /data/app-lib/net.alphawave.test.nativelibs-1/libmain.so 0x41e646a0
E/dalvikvm( 7846): dlopen("/data/app-lib/com.example.test.nativelibs-1/libmain.so") failed: dlopen failed: cannot locate symbol "unum_countAvailable_53" referenced by "libmain.so"...
W/dalvikvm( 7846): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/test/nativelibs/NativeLibs;
W/dalvikvm( 7846): Class init failed in newInstance call (Lcom/example/test/nativelibs/NativeLibs;)
D/AndroidRuntime( 7846): Shutting down VM
W/dalvikvm( 7846): threadid=1: thread exiting with uncaught exception (group=0x41591ba8)
E/AndroidRuntime( 7846): FATAL EXCEPTION: main
E/AndroidRuntime( 7846): Process: com.example.test.nativelibs, PID: 7846
E/AndroidRuntime( 7846): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "unum_countAvailable_53" referenced by "libmain.so"...
我试过预加载这些库,但这似乎没有帮助:
static {
System.loadLibrary("icuuc");
System.loadLibrary("icui18n");
System.loadLibrary("main");
}
这导致:
D/dalvikvm( 8277): Trying to load lib /data/app-lib/com.example.test.nativelibs-1/libicuuc.so 0x41e6d310
D/dalvikvm( 8277): Added shared lib /data/app-lib/com.example.test.nativelibs-1/libicuuc.so 0x41e6d310
D/dalvikvm( 8277): No JNI_OnLoad found in /data/app-lib/com.example.test.nativelibs-1/libicuuc.so 0x41e6d310, skipping init
D/dalvikvm( 8277): Trying to load lib /data/app-lib/com.example.test.nativelibs-1/libicui18n.so 0x41e6d310
D/dalvikvm( 8277): Added shared lib /data/app-lib/com.example.test.nativelibs-1/libicui18n.so 0x41e6d310
D/dalvikvm( 8277): No JNI_OnLoad found in /data/app-lib/com.example.test.nativelibs-1/libicui18n.so 0x41e6d310, skipping init
D/dalvikvm( 8277): Trying to load lib /data/app-lib/com.example.test.nativelibs-1/libmain.so 0x41e6d310
E/dalvikvm( 8277): dlopen("/data/app-lib/com.example.test.nativelibs-1/libmain.so") failed: dlopen failed: cannot locate symbol "unum_countAvailable_53" referenced by "libmain.so"...
符号存在于 icui18n 库中:
$ arm-linux-gnueabi-readelf -aW libicui18n.so | grep unum_countAvailable
3700: 000ee8a9 4 FUNC GLOBAL DEFAULT 7 unum_countAvailable_53
我错过了什么?还是 icu* 构建需要一些 mod?
谢谢,
链接库(53 版)和 /system 库(51 版)不匹配,运行-time 链接器正在使用后者。
我问了修改过的问题!