Tôi đang cố gắng sử dụng Google Test với NDK của Android. Sau khi NDK README example here, tôi đã thiết lập Android.mk tôi và một bài kiểm tra đơn như dưới đây, nhưng tôi nhận được lỗi này:tham chiếu không xác định đối với 'typeinfo để thử nghiệm :: Kiểm tra' với Google Test trên 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
Dưới đây là những gì tôi biết cho đến nay:
::testing::Test
là lớp Google Test tự động được phân loại theo macroTEST()
.undefined reference to 'typeinfo for
lỗi thường xảy ra khi trình liên kết không thể tìm thấy định nghĩa cho phương thức ảo.- could be caused by compiling google test with different flags, nhưng không phải là trường hợp ở đây kể từ khi tôi đang sử dụng thư viện google thử nghiệm tĩnh và những lá cờ đều giống nhau giữa hai mô-đun.
tôi đang thiếu gì? Hoặc tôi có thể xem tiếp theo ở đâu? Cảm ơn!
update: tôi có thể xây dựng một thử nghiệm của Google đơn giản mà không phụ thuộc vào bất cứ điều gì giống như Boost hoặc apis mẹ đẻ Android nếu tôi loại bỏ các SHARED_LIBRARIES, CPP_FLAGS, và LDLIBS từ các module ndkfoo_unittest.
lệnh xây dựng:
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)
Bạn cần phải cho chúng ta thấy mối liên kết dòng lệnh cho 'ndkfoo_unittest' từ đó kết quả lỗi. –
@MikeKinghan Chắc chắn điều. Tôi đã thêm nó vào câu hỏi. Và tôi có các biến môi trường cho những thứ như 'BOOST_INCLUDE_PARENT'. Những người đang làm việc một cách chính xác. – mxdubois
Đó không phải là lệnh mối liên kết, đó là 'lệnh ndk-build'. Sau khi xây dựng biên dịch file nguồn của bạn nó gọi mối liên kết ('ld') để tạo ra thực thi của bạn. Chúng ta cần dòng lệnh 'ld' mà nó tạo ra. Bạn đang hiển thị cho chúng tôi lỗi liên kết nhưng không hiển thị cho chúng tôi những gì đang được liên kết. –