Android GNU STL shared library not found using System.loadLibrary

I have compiled a shared library with android-cmake and NDK against libstdC ++, as well as android-ndk-r7 / docs / CPLUSPLUS-SUPPORT.html. I am trying to download gnustl_shared before downloading my library:

static { System.loadLibrary("gnustl_shared"); System.loadLibrary("MathTest"); } 

I see this being done, for example, here , but I get an exception:

 01-03 20:02:42.307: E/AndroidRuntime(569): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gnustl_shared: findLibrary returned null 

If I do not download gnustl_shared, it is not with this exception:

 01-03 20:03:04.667: E/AndroidRuntime(603): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1311]: 33 cannot locate '_ZNSo3putEc'... 

I tested API levels 8 and 9 with the same problem. What am I doing wrong? I assume that the character that he is looking for in the last exception is related to the STL, and that loading it will solve the problem. This is true?

Edit: Now I have included the STL library, as suggested in the answers. The compilation line that CMake produces is (note that my project has three files, mother.c (a copy of the Master George Marsaliga Matter All Random Number Generator is available here ), Driver.cpp , which contains functions for testing various mathematical libraries and printout of the runtime of functions and androidactivity.cpp , which contains the JNI glue, and calls the test function from Driver.cpp . The detailed Makefile output generated by CMake is as follows. I'm not sure if this is useful information, but

 [ 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.co /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.co -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 shows that my library depends on libstdc++ , libm , libc and libdl , and as far as I know, all of them, except libstdc++ , are available on the device according to 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 

Does this information help? Is there a way by which I can determine where an unreasonable symbol came from?

+4
source share
6 answers

well, you need to load gnustl_shared in front of your own libraries, something like this:

 static { System.loadLibrary("gnustl_shared"); System.loadLibrary("myNativeLib1"); System.loadLibrary("myNativeLib2"); //....... } 
+1
source

You probably also need to add it to your Application.mk. The project that you linked did this at a minimum .

0
source

I suppose you will need to package the appropriate libgnustl_shared.so (one for each ABI you are going to work with) in your APK libs / *. What this means specifically for your custom CMake build system, I cannot tell you.

APKs are just zip files - you can open your version and ensure its presence where it was expected.

0
source

You show the g ++ commands created by cmake . They look normal. But the linker created libMathTest.so based on the STL system library. This is actually a mixture of system STL and gnustl (some links to the latter were probably obtained from cxx-stl / gnu-libstdC ++ / include ).

This will help if you echo the actual command in

 Linking CXX shared library ../../android/libs/armeabi/libMathTest.so 

But maybe your application can be satisfied with the STL library of the system? An important advantage is that libstdc ++ is therefore preinstalled on all devices like libm .

0
source

In my case, the gnustl_shared library is not actually located on the device (it is running Android 2.3.6). When I bind gnustl statically, the NDK application works fine on the device. my 2 cents

0
source

I met the same problem, however I made a large assembly with 6 shared libraries, it all depends on libgnustl_shared.so, and I made two abi assemblies: armeabi and armeabi-v7a All shared libraries were manually copied to libs / (abi-name) / , inclusive libgnustl-shared.so. I did System.load ("gnustl_shared") first, but whenever android activity tried to load lib, it was thrown out and said that gnustl_shared was not found. I tried with Androip-8, android-9 and android-14, they all have the same error.

 _HERE THE ANDROID.MK_ MYTOP_DIR := $(call my-dir) LOCAL_PATH := $(MYTOP_DIR) include $(CLEAR_VARS) NDK_ROOT := /home/workspace/android-ndk-r7 RUNTIME_STL_PATH :=$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++ # name of the module to be built LOCAL_MODULE := MyMediaPlayer LOCAL_SRC_FILES := MyMediaPlayer.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/libMediaClient/include # rule definition LOCAL_CPP_EXTENSION := .cxx .cpp .cc LOCAL_CFLAGS += -I$(RUNTIME_STL_PATH)/include LOCAL_CFLAGS += -I$(RUNTIME_STL_PATH)/libs/$(TARGET_ARCH_ABI)/include LOCAL_LDLIBS += -llog LOCAL_LDLIBS += -landroid LOCAL_LDLIBS += -L$(RUNTIME_STL_PATH)/libs/$(TARGET_ARCH_ABI) LOCAL_LDLIBS += -lgnustl_shared LOCAL_LDLIBS += -L$(LOCAL_PATH)/libMediaClient/lib/android/$(TARGET_ARCH_ABI) LOCAL_LDLIBS += -lMediaClient LOCAL_LDLIBS += -ltools include $(BUILD_SHARED_LIBRARY) _HERE THE APPLICATION.MK_ APP_ABI := armeabi armeabi-v7a APP_STL := gnustl_shared # this doesn't make any sense APP_MODULES := MyMediaPlayer 

I could understand if an exception occurred while loading my own libraries, but here libgnustil_shared really came from ndk, what is wrong here !!!

Stephen

-2
source

Source: https://habr.com/ru/post/1389139/


All Articles