Syntax error on using gtest with Android NDK

883 views Asked by At

I am trying use gtest with ndk, the ndk-build finds the dependences, but I have a sintax error on internal gtest file gtest-printers.h

external/gtest/include/gtest/gtest-printers.h:170:9: error: ambiguous overload for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char, std::char_traits<char> >}' and 'const BiggestInt {aka const long long int}')
     *os << kBigInt;
         ^

follows my Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := my_module

GTEST_DIR := $(LOCAL_PATH)/../../external/gtest

LOCAL_CPP_EXTENSION := .cxx .cpp .cc

LOCAL_CFLAGS := -D_STLP_USE_NEWALLOC

LOCAL_CPPFLAGS += -std=c++11

LOCAL_SRC_FILES :=                             \
    ...

LOCAL_C_INCLUDES :=                            \
    ...

LOCAL_C_INCLUDES += ${NDK_ROOT}/sources/cxx-stl/stlport/stlport
LOCAL_C_INCLUDES += ${GTEST_DIR}/include

LOCAL_LDLIBS    += -llog
LOCAL_LDLIBS    += -landroid
LOCAL_LDLIBS    += -lstdc++

LOCAL_STATIC_LIBRARIES := $(GTEST_DIR)/lib/libgtest.a

include $(BUILD_EXECUTABLE)
3

There are 3 answers

0
Alex On BEST ANSWER

My problem was try to call static gtest lib directly, instead of, I had to do it before:

include $(CLEAR_VARS)
GTEST_DIR := ${NDK_ROOT}/sources/third_party/googletest/googletest
LOCAL_MODULE    := gtest

# flag for c++11
LOCAL_CPPFLAGS += -std=c++11

LOCAL_C_INCLUDES += ${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include
LOCAL_C_INCLUDES += ${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.9/include/
LOCAL_C_INCLUDES += ${GTEST_DIR}/include/
LOCAL_C_INCLUDES += ${GTEST_DIR}/

LOCAL_SRC_FILES := ${GTEST_DIR}/src/gtest-all.cc              \
                   ${GTEST_DIR}/src/gtest.cc                  \
                   ${GTEST_DIR}/src/gtest-death-test.cc       \
                   ${GTEST_DIR}/src/gtest-filepath.cc         \
                   ${GTEST_DIR}/src/gtest_main.cc             \
                   ${GTEST_DIR}/src/gtest-port.cc             \
                   ${GTEST_DIR}/src/gtest-printers.cc         \
                   ${GTEST_DIR}/src/gtest-test-part.cc        \
                   ${GTEST_DIR}/src/gtest-typed-test.cc

LOCAL_STATIC_LIBRARIES += ${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/thumb/libgnustl_static.a

include $(BUILD_STATIC_LIBRARY)
0
Dan Albert On

It looks like C++11 + stlport is the bad combination for gtest. This isn't terribly surprising, given that stlport doesn't actually have any support for C++11 (some parts of it will work, others apparently won't). If this only causes problems when building gtest, you could just not use C++11 when building gtest, but still for your code.

If you can't use it from C++11 either, you're probably out of luck for now (there should be a better option available as soon as I find time).

0
Lukasz Gut On

We have encountered the same issue, and working solution was to use:

LOCAL_CPPFLAGS += -std=gnu++11

instead of LOCAL_CPPFLAGS+=-std=c++11. It must have set some different mappings of long long int in stlport.