Sto provando a utilizzare Google Test con NDK Android. A seguito del NDK README example here, ho impostato il mio Android.mk e un singolo test, come di seguito, ma io sto ottenendo questo errore:riferimento non definito a "typeinfo per test :: Test" con Google Test su Android NDK
./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
Ecco quello che so finora:
::testing::Test
è la classe di test di Google viene automaticamente suddivisa in sottoclassi dalla macroTEST()
.- Gli errori
undefined reference to 'typeinfo for
si verificano in genere quando il linker non riesce a trovare la definizione per un metodo virtuale. - could be caused by compiling google test with different flags, ma non dovrebbe essere il caso qui poiché sto usando la libreria di test google statico e le bandiere sono le stesse tra i due moduli.
Cosa mi manca? O dove posso guardare dopo? Grazie!
aggiornamento: posso costruire un semplice test di Google che non dipende da nulla come Boost o le API native di Android se mi tolgo la SHARED_LIBRARIES, CPP_FLAGS e LDLIBS dal modulo ndkfoo_unittest.
comando build:
ndk-build SHELL=/bin/bash NDK_DEBUG=1
FilteredPriorityQueue_test.cpp:
#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<(const MaskedObject& rhs) const {
return this->mMask < rhs.mMask;
}
};
typedef
FilteredPriorityQueue<int, MaskedObject, Comparator<MaskedObject> > TestQueue;
TEST(FilteredPriorityQueueTest,ShouldRetrieveTop) {
Comparator<MaskedObject> comparator(Comparator<MaskedObject>::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());
}
Android.mk:
# 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)
Devi mostrare la riga di comando del linker per 'ndkfoo_unittest' da cui proviene l'errore. –
@ MikeKinghan Una cosa sicura. L'ho aggiunto alla domanda. E ho variabili d'ambiente per cose come 'BOOST_INCLUDE_PARENT'. Funzionano correttamente. – mxdubois
Questo non è il comando linker, è il comando 'ndk-build'. Dopo che la compilazione ha compilato i tuoi file sorgente, richiama il linker ('ld') per creare il tuo eseguibile. Abbiamo bisogno della linea di comando 'ld' che genera. Ci stai mostrando un errore di collegamento ma non ci mostra cosa viene collegato. –