Próbuję użyć Google Test z Android NDK. Po NDK README example here, mam skonfigurować Android.mk i jeden test jak poniżej, ale ja dostaję ten błąd:Nieokreślone odniesienie do "typeinfo for testing :: Test" z Google Test na Androida 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
Oto, co wiem do tej pory:
::testing::Test
jest klasa testów Google automatycznie podklasyfikowana w makrzeTEST()
.undefined reference to 'typeinfo for
Błędy pojawiają się zwykle, gdy linker nie może znaleźć definicji dla metody wirtualnej.- could be caused by compiling google test with different flags, ale nie powinno tak być w tym przypadku, ponieważ używam statycznej biblioteki testowej google, a flagi są takie same między tymi dwoma modułami.
Czego mi brakuje? Lub gdzie mogę spojrzeć dalej? Dzięki!
zmiana: mogę zbudować prosty Google test, który nie zależy od niczego podobnego podwyższenie lub Android natywnych API Jeśli usunąć SHARED_LIBRARIES, CPP_FLAGS i LDLIBS z ndkfoo_unittest modułu.
Budowa polecenie:
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)
Musisz nam pokazać wiersz komend dla 'ndkfoo_unittest', z którego wynika błąd. –
@MikeKinghan Pewnie. Dodałem go do pytania. I mam zmienne środowiskowe dla rzeczy takich jak 'BOOST_INCLUDE_PARENT'. Działają poprawnie. – mxdubois
To nie jest polecenie linkera, to polecenie 'ndk-build'. Po kompilacji kompilacji plików źródłowych wywołuje linker ('ld'), aby utworzyć plik wykonywalny. Potrzebujemy wiersza polecenia 'ld', który generuje. Pokazujesz nam błąd połączenia, ale nie pokazuje nam, co jest połączone. –