title: undefined reference to 'typeinfo for testing::Test' with Google Test on Android NDK
body: <p>I'm trying to use Google Test with the Android NDK. Following the <a href="http://mobilepearls.com/labs/native-android-api/ndk/sources/third_party/googletest/README.NDK">NDK README example here</a>, I've set up my Android.mk and a single test as below, but I'm getting this error:</p>
  
  <pre><code>./obj/local/armeabi/objs-debug/ndkfoo_unittest/FilteredPriorityQueue_test.o:FilteredPriorityQueue_test.cpp:function typeinfo for mashbot::FilteredPriorityQueueTest_ShouldRetrieveTop_Test: error: undefined reference to 'typeinfo for testing::Test'
  collect2: error: ld returned 1 exit status
  make: *** [obj/local/armeabi/ndkfoo_unittest] Error 1    
  </code></pre>
  
  <p>Here's what I know so far:</p>
  
  <ul>
  <li><code>::testing::Test</code> is the Google Test class automatically subclassed by the <code>TEST()</code> macro.</li>
  <li><code>undefined reference to 'typeinfo for</code> errors usually occur when the linker can't find the definition for a virtual method.</li>
  <li><a href="https://groups.google.com/forum/#!topic/googletestframework/yGqN-6C_SaM">could be caused by compiling google test with different flags</a>, but shouldn't be the case here since I'm using the static google test library and the flags are the same between the two modules.</li>
  </ul>
  
  <p>What am I missing? Or where can I look next? Thanks!</p>
  
  <p><strong>update:</strong> I can build a simple Google Test that does not depend on anything like Boost or the Android native apis if I remove the SHARED_LIBRARIES, CPP_FLAGS, and LDLIBS from the ndkfoo_unittest module.</p>
  
  <p>Build command:</p>
  
  <pre><code>ndk-build SHELL=/bin/bash NDK_DEBUG=1
  </code></pre>
  
  <p>FilteredPriorityQueue_test.cpp:</p>
  
  <pre><code>#include "gtest/gtest.h"
  
  // FilteredPriorityQueue is a header-only file with no virtual methods.
  #include "FilteredPriorityQueue.h"
  
  // So is Comparator.
  #include "Comparator.h"
  
  struct MaskedObject {
      int mMask;
      MaskedObject(int mask) : mMask(mask) { }
      int getMask() const { return mMask; }
      bool operator&lt;(const MaskedObject&amp; rhs) const {
             return this-&gt;mMask &lt; rhs.mMask;
      }
  };
  
  typedef
  FilteredPriorityQueue&lt;int, MaskedObject, Comparator&lt;MaskedObject&gt; &gt; TestQueue;
  
  TEST(FilteredPriorityQueueTest,ShouldRetrieveTop) {
      Comparator&lt;MaskedObject&gt; comparator(Comparator&lt;MaskedObject&gt;::LESS);
      TestQueue q(comparator);
      q.push(1, MaskedObject(1));
      q.push(2, MaskedObject(2));
      q.push(4, MaskedObject(4));
      EXPECT_EQ( 1, q.top().getMask() );
  }
  </code></pre>
  
  <p>Android.mk:</p>
  
  <pre><code># ndkfoo module
  #-------------------------
  LOCAL_MODULE    := ndkfoo
  
  LOCAL_CPPFLAGS := -frtti -pthread -fexceptions -std=c++11
  LOCAL_LDLIBS   += -lOpenSLES -llog -landroid
  
  LOCAL_C_INCLUDES += $(LIBMASHBOT_ROOT)/include
  LOCAL_C_INCLUDES += $(BOOST_INCLUDE_PARENT)
  
  LOCAL_SHARED_LIBRARIES += mashbot \
          gnustl_shared \
          boost_thread-gcc-mt-1_53 \
          boost_system-gcc-mt-1_53 \
          $(BOOST_LIB)
  
  LOCAL_SRC_FILES := ndkfoo.cpp \
          #...more files...
  
  include $(BUILD_SHARED_LIBRARY)
  
  
  # ndkfoo tests module
  #-------------------------
  include $(CLEAR_VARS)
  LOCAL_MODULE := ndkfoo_unittest
  
  LOCAL_CPPFLAGS := -frtti -pthread -fexceptions -std=c++11
  
  LOCAL_C_INCLUDES += $(BOOST_INCLUDE_PARENT)
  
  LOCAL_STATIC_LIBRARIES := googletest_main
  LOCAL_SHARED_LIBRARIES += ndkfoo \
          gnustl_shared \
          $(BOOST_LIB)
  
  LOCAL_SRC_FILES := FilteredPriorityQueue_test.cpp
  
  include $(BUILD_EXECUTABLE)
  
  # this imports $NDK/sources/third_party/googletest/Android.mk
   $(call import-module,third_party/googletest)
  </code></pre>