我有一个测试应用程序,我试图与ibicuuc和libicui18n链接。 (这是大型项目的第一步。)
我将这些包含在我的项目中作为预建库
LOCAL_SHARED_LIBRARIES := libicuuc libicui18n
从git存储库中按原样编译:
https://android.googlesource.com/platform/external/icu4c/
这是clean的构建日志:
$ 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 * build需要一些mod吗?
谢谢,
答案 0 :(得分:0)
链接库(版本53)和/系统库(版本51)之间不匹配,运行时链接器使用后者。
我问了一个修改过的问题!