Syntax error when using gtest with Android NDK

advertisements

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)


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.