我編譯了一個共享庫與android-cmake和NDK對libstdC++,並根據android-ndk-r7/docs/CPLUSPLUS-SUPPORT.html我試圖加載我的圖書館前加載gnustl_shared:Android的GNU STL共享庫無法找到與System.loadLibrary
static {
System.loadLibrary("gnustl_shared");
System.loadLibrary("MathTest");
}
我可以看到這個正在做,例如here,但我得到一個異常:
01-03 20:02:42.307: E/AndroidRuntime(569): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gnustl_shared: findLibrary returned null
如果我不加載gnustl_shared,它以下例外情況失敗:
01-03 20:03:04.667: E/AndroidRuntime(603): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1311]: 33 cannot locate '_ZNSo3putEc'...
我已經在API級別8和9上測試過相同的問題。我究竟做錯了什麼?我假設它在最後一個異常中尋找的符號與STL相關,並且加載它會解決問題。是這樣嗎?
編輯: 我現在已經包含了答案建議的STL庫。 (注意我的項目有三個文件,mother.c
(George Marsaliga的所有隨機數生成器的母親的副本可用here),Driver.cpp
其中包含函數來測試不同的數學庫並打印出函數運行時,和androidactivity.cpp
其中包含JNI膠水,並呼籲從Driver.cpp
測試功能。通過CMake的生成詳細的Makefile輸出如下。我不知道這是否是有用的信息,但
[ 33%] Building CXX object CMakeFiles/MathTest.dir/src/Driver.cpp.o
/Users/martin/Android/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -DMathTest_EXPORTS -D__STDC_INT64__ --sysroot=/Users/martin/Android/android-ndk-r7/platforms/android-8/arch-arm -fPIC -DANDROID -Wno-psabi -fsigned-char -mthumb -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -fexceptions -fno-check-new -fno-common -fstrict-aliasing -Wno-variadic-macros -Wextra -pedantic -g0 -O2 -fPIC -isystem /Users/martin/Android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include -isystem /Users/martin/Android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include -I/Users/martin/Repositories/MathTest/lib/cml-1_0_2 -I/Users/martin/Repositories/MathTest/lib/eigen-eigen-13a11181fc5a -I/Users/martin/Repositories/MathTest/lib/glm-0.9.3.B -o CMakeFiles/MathTest.dir/src/Driver.cpp.o -c /Users/martin/Repositories/MathTest/src/Driver.cpp
"/Applications/CMake 2.8-4.app/Contents/bin/cmake" -E cmake_progress_report /Users/martin/Repositories/MathTest/build/android/CMakeFiles 2
[ 66%] Building C object CMakeFiles/MathTest.dir/src/mother.c.o
/Users/martin/Android/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gcc -DMathTest_EXPORTS -D__STDC_INT64__ --sysroot=/Users/martin/Android/android-ndk-r7/platforms/android-8/arch-arm -fPIC -DANDROID -Wno-psabi -fsigned-char -mthumb -O3 -DNDEBUG -fPIC -I/Users/martin/Android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include -I/Users/martin/Android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include -I/Users/martin/Repositories/MathTest/lib/cml-1_0_2 -I/Users/martin/Repositories/MathTest/lib/eigen-eigen-13a11181fc5a -I/Users/martin/Repositories/MathTest/lib/glm-0.9.3.B -o CMakeFiles/MathTest.dir/src/mother.c.o -c /Users/martin/Repositories/MathTest/src/mother.c
"/Applications/CMake 2.8-4.app/Contents/bin/cmake" -E cmake_progress_report /Users/martin/Repositories/MathTest/build/android/CMakeFiles 3
[100%] Building CXX object CMakeFiles/MathTest.dir/src/androidactivity.cpp.o
/Users/martin/Android/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -DMathTest_EXPORTS -D__STDC_INT64__ --sysroot=/Users/martin/Android/android-ndk-r7/platforms/android-8/arch-arm -fPIC -DANDROID -Wno-psabi -fsigned-char -mthumb -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -fexceptions -fno-check-new -fno-common -fstrict-aliasing -Wno-variadic-macros -Wextra -pedantic -g0 -O2 -fPIC -isystem /Users/martin/Android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/include -isystem /Users/martin/Android/android-ndk-r7/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include -I/Users/martin/Repositories/MathTest/lib/cml-1_0_2 -I/Users/martin/Repositories/MathTest/lib/eigen-eigen-13a11181fc5a -I/Users/martin/Repositories/MathTest/lib/glm-0.9.3.B -o CMakeFiles/MathTest.dir/src/androidactivity.cpp.o -c /Users/martin/Repositories/MathTest/src/androidactivity.cpp
Linking CXX shared library ../../android/libs/armeabi/libMathTest.so
readelf
表明我的庫依賴在libstdc++
,libm
,libc
和libdl
,據我所知除了libstdc++
以外,所有這些都可以在設備上按照android-ndk-r7/docs/STABLE-APIS.html
獲得。
Martin-Foots-MacBook-Pro:android martin$ ~/Android/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-readelf -d ../../android/libs/armeabi/libMathTest.so
Dynamic section at offset 0x14b0 contains 25 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libstdc++.so]
0x00000001 (NEEDED) Shared library: [libm.so]
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
0x0000000e (SONAME) Library soname: [libMathTest.so]
0x00000010 (SYMBOLIC) 0x0
0x00000019 (INIT_ARRAY) 0x9498
0x0000001b (INIT_ARRAYSZ) 12 (bytes)
0x0000001a (FINI_ARRAY) 0x94a4
0x0000001c (FINI_ARRAYSZ) 12 (bytes)
0x00000004 (HASH) 0xd4
0x00000005 (STRTAB) 0x544
0x00000006 (SYMTAB) 0x234
0x0000000a (STRSZ) 1033 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x9598
0x00000002 (PLTRELSZ) 136 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x990
0x00000011 (REL) 0x950
0x00000012 (RELSZ) 64 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000016 (TEXTREL) 0x0
0x6ffffffa (RELCOUNT) 4
0x00000000 (NULL) 0x0
該信息有幫助嗎?有沒有一種方法可以告訴我這個未知的符號來自哪裏?
不幸的是,這並沒有幫助,因爲我沒有使用ndk-build。我使用CMake來編譯我所有的源代碼。 – 2012-01-04 16:38:39