title: Android's GNU STL shared library can't be found with System.loadLibrary
body: <p>I've compiled a shared library with android-cmake and the NDK against libstdc++, and as per android-ndk-r7/docs/CPLUSPLUS-SUPPORT.html I'm trying to load gnustl_shared before loading my library:</p>
  
  <pre><code>static {
      System.loadLibrary("gnustl_shared");
      System.loadLibrary("MathTest");
  }
  </code></pre>
  
  <p>I can see this being done for instance <a href="http://code.google.com/p/ting/source/browse/trunk/android/src/com/googlecode/ting/SharedLibLoaderNativeActivity.java?spec=svn653&amp;r=653" rel="nofollow">here</a> but I get an exception:</p>
  
  <pre><code>01-03 20:02:42.307: E/AndroidRuntime(569): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gnustl_shared: findLibrary returned null
  </code></pre>
  
  <p>If I don't load gnustl_shared, it fails with this exception:</p>
  
  <pre><code>01-03 20:03:04.667: E/AndroidRuntime(603): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1311]:    33 cannot locate '_ZNSo3putEc'...
  </code></pre>
  
  <p>I have tested on API levels 8 and 9 with the same issue. What am I doing wrong? I assume that the symbol it's looking for in the last exception is related to the STL and that loading it would solve the problem. Is this the case? </p>
  
  <p><strong>Edit:</strong>
  I've now included the STL library as suggested by answers. The compile line that CMake produces is this (note that my project has three files, <code>mother.c</code> (a copy of George Marsaliga's Mother of All Random Number Generator available <a href="ftp://ftp.forth.org/pub/C/mother.c" rel="nofollow">here</a>), <code>Driver.cpp</code> which contains functions to test different math libraries and print out the function runtimes, and <code>androidactivity.cpp</code> which contains the JNI glue and calls the test function from <code>Driver.cpp</code>. The verbose Makefile output generated by CMake is as follows. I'm not sure if this is useful information but </p>
  
  <pre><code>[ 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
  </code></pre>
  
  <p><code>readelf</code> shows that my library depends on <code>libstdc++</code>, <code>libm</code>, <code>libc</code> and <code>libdl</code>, and as far as I know all of these except <code>libstdc++</code> are available on the device as per <code>android-ndk-r7/docs/STABLE-APIS.html</code>.</p>
  
  <pre><code>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    
  </code></pre>
  
  <p>Does this information help? Is there a way I can tell where the unfound symbol comes from?</p>