title: Error Undefined reference to 'std::__ndk1::locale::~locale()'
body: <p>I have an issue when compiling my code using <a href="https://github.com/moritz-wundke/Boost-for-Android" rel="nofollow noreferrer">Boost for Android</a> with Android Studio ndk.
  I am using one of the libraries libboost_filesystem-clang-mt-a32-1_66.a from boost, however, it shows following error:</p>
  
  <pre><code>FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':app:externalNativeBuildDebug'.
  &gt; Build command failed.
    Error while executing process /home/user/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/user/git/project/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target native-lib}
    [1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
    [2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
    FAILED: : &amp;&amp; /home/user/Downloads/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++  --sysroot=/home/user/Downloads/android-ndk-r16b/sysroot -fPIC -isystem /home/user/Downloads/android-ndk-r16b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=23 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -mfpu=neon -Wa,--noexecstack -Wformat -Werror=format-security  -std=c++11 -Wno-error=format-security -fpermissive -fopenmp -Og -fopenmp -O0  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot /home/user/Downloads/android-ndk-r16b/platforms/android-23/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -L/home/user/git/project/app/src/main/cpp/libs -laltumfacerecognizesdk_android -laltumfacedetectsdk_android ../../../../src/main/jniLibs/armeabi-v7a/libopencv_java.so /home/user/git/project/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_core.a /home/user/git/project/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_highgui.a /home/user/git/project/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_imgproc.a /home/user/git/project/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_video.a /home/user/Downloads/android-ndk-r16b/platforms/android-23/arch-arm/usr/lib/liblog.so ../../../../src/main/cpp/libs/libgnustl_shared.so -lncnn -lboost_filesystem-clang-mt-a32-1_66 -lboost_system-clang-mt-a32-1_66 /home/user/git/project/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_androidcamera.a /home/user/git/project/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibjpeg.a /home/user/git/project/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibpng.a /home/user/git/project/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibtiff.a /home/user/git/project/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibjasper.a /home/user/git/project/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/libIlmImf.a /home/user/git/project/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_imgproc.a /home/user/git/project/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_core.a -lz -ldl -lm -llog -ldl -lm -llog -latomic -lm "/home/user/Downloads/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libsupc++.a" "/home/user/Downloads/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_shared.so" &amp;&amp; :
    ./boost/system/system_error.hpp:31: error: undefined reference to 'std::runtime_error::runtime_error(std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits&lt;char&gt;, std::__ndk1::allocator&lt;char&gt; &gt; const&amp;)'
    ./boost/system/system_error.hpp:31: error: undefined reference to 'std::runtime_error::runtime_error(std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits&lt;char&gt;, std::__ndk1::allocator&lt;char&gt; &gt; const&amp;)'
    /home/user/Downloads/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/stdexcept:136: error: undefined reference to 'std::logic_error::logic_error(char const*)'
    ./boost/system/system_error.hpp:31: error: undefined reference to 'std::runtime_error::runtime_error(std::__ndk1::basic_string&lt;char, std::__ndk1::char_traits&lt;char&gt;, std::__ndk1::allocator&lt;char&gt; &gt; const&amp;)'
    libs/filesystem/src/path.cpp:897: error: undefined reference to 'std::__ndk1::locale::locale(char const*)'
    /home/user/Downloads/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/__locale:212: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&amp;) const'
    libs/filesystem/src/path.cpp:914: error: undefined reference to 'std::__ndk1::locale::~locale()'
    libs/filesystem/src/path.cpp:914: error: undefined reference to 'std::__ndk1::codecvt&lt;wchar_t, char, mbstate_t&gt;::id'
    libs/filesystem/src/path.cpp:897: error: undefined reference to 'std::__ndk1::locale::locale(char const*)'
    libs/filesystem/src/path.cpp:947: error: undefined reference to 'std::__ndk1::locale::locale(std::__ndk1::locale const&amp;)'
    libs/filesystem/src/path.cpp:897: error: undefined reference to 'std::__ndk1::locale::locale(char const*)'
    libs/filesystem/src/path.cpp:948: error: undefined reference to 'std::__ndk1::locale::operator=(std::__ndk1::locale const&amp;)'
    libs/filesystem/src/path.cpp:950: error: undefined reference to 'std::__ndk1::locale::~locale()'
    libs/filesystem/src/path.cpp:914: error: undefined reference to 'std::__ndk1::locale::~locale()'
    libs/filesystem/src/path.cpp:914: error: undefined reference to 'std::__ndk1::locale::~locale()'
    /home/user/Downloads/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/stdexcept:146: error: undefined reference to 'std::logic_error::logic_error(char const*)'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
  
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  
  * Get more help at https://help.gradle.org
  
  BUILD FAILED in 2s
  </code></pre>
  
  <p>I had tried to use -DANDROID_STL=gnu_shared or -DANDROID_STL=gnu_static and got the same result. Spent a day on it, I still cannot make it compilable. </p>
  
  <p>In CMakeList:</p>
  
  <pre><code>add_library(lib_opencv SHARED IMPORTED)
  add_library(lib_gnustl_shared SHARED IMPORTED)
  
  set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java.so)
  set_target_properties(lib_gnustl_shared PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/cpp/libs/libgnustl_shared.so)
  target_link_libraries( # Specifies the target library.
                     native-lib
                     lib_opencv
                     # Links the target library to the log library
                     # included in the NDK.
                     ${OpenCV_LIBS}
                     ${log-lib}
                     boost_filesystem-clang-mt-a32-1_66
                     boost_system-clang-mt-a32-1_66
                     lib_gnustl_shared
                      )
  </code></pre>
  
  <p>In gradle:</p>
  
  <pre><code>        externalNativeBuild {
          cmake {
              arguments "-DANDROID_TOOLCHAIN=gcc","-DANDROID_ARM_NEON=TRUE" ,"-DANDROID_STL_FORCE_FEATURES=OFF", "-DANDROID_STL=gnustl_shared"
              cppFlags "-std=c++11", "-Wno-error=format-security", "-fpermissive", "-fopenmp", "-Og"
          }
  </code></pre>