title: Android NDK make. Hundreds of "undefined reference error"s
body: <p>When trying to build this sample project <a href="https://github.com/caffe2/AICamera/tree/master/app/src/main/cpp" rel="nofollow noreferrer">https://github.com/caffe2/AICamera/tree/master/app/src/main/cpp</a> I get hundres of <code>error: undefined reference</code>s. Here are the first few lines of output:</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/aidan/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/aidan/AndroidStudioProjects/AICamera/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target native-lib}
    [1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
    FAILED: : &amp;&amp; /home/aidan/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/aidan/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/aidan/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem /home/aidan/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=22 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -std=c++11 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /home/aidan/Android/Sdk/ndk-bundle/platforms/android-22/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -L/home/aidan/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -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  -Wl,--whole-archive ../../../../src/main/jniLibs/armeabi-v7a/libCaffe2_CPU.a -Wl,--no-whole-archive ../../../../src/main/jniLibs/armeabi-v7a/libCAFFE2_NNPACK.a ../../../../src/main/jniLibs/armeabi-v7a/libCAFFE2_PTHREADPOOL.a ../../../../src/main/jniLibs/armeabi-v7a/libglog.so ../../../../src/main/jniLibs/armeabi-v7a/libprotobuf.a libcpufeatures.a /home/aidan/Android/Sdk/ndk-bundle/platforms/android-22/arch-arm/usr/lib/liblog.so /home/aidan/Android/Sdk/ndk-bundle/platforms/android-22/arch-arm/usr/lib/libandroid.so -ldl -latomic -lm "/home/aidan/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a" "/home/aidan/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++abi.a" "/home/aidan/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a" "-ldl" &amp;&amp; :
    ../../../../src/main/jniLibs/armeabi-v7a/libCaffe2_CPU.a(nnpack_ops.cc.o):nnpack_ops.cc:function std::_Sp_counted_deleter&lt;void*, void (*)(void*), std::allocator&lt;void&gt;, (__gnu_cxx::_Lock_policy)2&gt;::_M_get_deleter(std::type_info const&amp;): error: undefined reference to 'std::type_info::operator==(std::type_info const&amp;) const'
    ../../../../src/main/jniLibs/armeabi-v7a/libCaffe2_CPU.a(nnpack_ops.cc.o):nnpack_ops.cc:function std::_Sp_counted_deleter&lt;void*, caffe2::Tensor&lt;caffe2::CPUContext&gt;::raw_mutable_data(caffe2::TypeMeta const&amp;)::{lambda(void*)#1}, std::allocator&lt;void&gt;, (__gnu_cxx::_Lock_policy)2&gt;::_M_get_deleter(std::type_info const&amp;): error: undefined reference to 'std::type_info::operator==(std::type_info const&amp;) const'
    ../../../../src/main/jniLibs/armeabi-v7a/libCaffe2_CPU.a(nnpack_ops.cc.o):nnpack_ops.cc:function void caffe2::TypeMeta::_CopyNotAllowed&lt;caffe2::Tensor&lt;caffe2::CPUContext&gt; &gt;(void const*, void*, unsigned int): error: undefined reference to 'std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*, int)'
  ... + 100s of similar lines, all with undefined references
  </code></pre>
  
  <p>This is my first attempt at Android NDK so I am new to this and have limited experience with building C++. From what I can see it seems to be a linking error since it can't seem to find <code>std</code>. Due to my limited experience, I'm having trouble seeing how I could troubleshoot this.</p>
  
  <p>Here is my <code>CMakeLists.txt</code> file</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.4.1)
  
  add_library(
               native-lib
               SHARED
               src/main/cpp/native-lib.cpp
               )
  find_library(
            android-lib
            android
            )
  
  include(AndroidNdkModules)
  android_ndk_import_module_cpufeatures()
  
  add_library(
      caffe2
      STATIC
      IMPORTED
      )
  set_target_properties(
      caffe2
      PROPERTIES IMPORTED_LOCATION
      ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libCaffe2_CPU.a
      )
  add_library(
      thread_pool
      STATIC
      IMPORTED
      )
  set_target_properties(
      thread_pool
      PROPERTIES IMPORTED_LOCATION
      ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libCAFFE2_PTHREADPOOL.a
      )
  add_library(
      glog
      SHARED
      IMPORTED
      )
  set_target_properties(
      glog
      PROPERTIES IMPORTED_LOCATION
      ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libglog.so
      )
  
  add_library(
      protobuf
      SHARED
      IMPORTED
      )
  set_target_properties(
      protobuf
      PROPERTIES IMPORTED_LOCATION
      ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libprotobuf.a
      )
  
  add_library(
      NNPACK
      STATIC
      IMPORTED
      )
  set_target_properties(
      NNPACK
      PROPERTIES IMPORTED_LOCATION
      ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libCAFFE2_NNPACK.a
      )
  
  include_directories( src/main/cpp )
  
  find_library(
       log-lib
       log
       )
  
  target_link_libraries(
                         native-lib
                         -Wl,--whole-archive
                         caffe2
                         -Wl,--no-whole-archive
                         NNPACK
                         thread_pool
                         glog
                         protobuf
                         cpufeatures
                         ${log-lib}
                         ${android-lib})
  </code></pre>