Rafael Ruiz Muñoz
Rafael Ruiz Muñoz

Reputation: 5472

error: 'to_string' is not a member of 'std'

It could be duplicate, but I tried all the solutions that I found on and out StackOverflow.

I'm making a library on C++ with OpenCV and trying to compile it for Android.

I can't use to_string(int)but I'm not able. I tried to modify my makefile too many times. My last configuration is this on:

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=off

OPENCV_INSTALL_MODULES:=on

include $(LOCAL_PATH)/jsoncpp/Android.mk

include /Users/rafaelruizmunoz/Desktop/AndroidDevelopment/OpenCV-2.4.9-android- sdk/sdk/native/jni/OpenCV.mk

OPENCV_LIB_TYPE:=SHARED

LOCAL_C_INCLUDES += $(LOCAL_PATH)

LOCAL_C_INCLUDES += /Users/rafaelruizmunoz/opencvscan/OpenCVtry/

LOCAL_C_INCLUDES += /Users/rafaelruizmunoz/Desktop/RD/OpenCVtry/Libraries/jsoncpp- master/include

LOCAL_PATH := jni

LOCAL_ALLOW_UNDEFINED_SYMBOLS := true

LOCAL_MODULE := libXYZ

LOCAL_MODULE_NAME := mylibXYZ

LOCAL_SRC_FILES := androidClass.cpp main.cpp utils.cpp

LOCAL_LDLIBS += -llog -ldl

LOCAL_CPPFLAGS := -std=c++11 CFLAGS=-g -Wall -Wextra -std=c++11 -Wno-write-strings ../../include/boost

LOCAL_SHARED_LIBRARIES := libJsoncpp libopencv_java

include $(BUILD_SHARED_LIBRARY)

and this is my Application.mk

APP_STL := gnustl_static

APP_CPPFLAGS := -frtti -fexceptions

APP_ABI := all

APP_MODULES := libXYZ libJsoncpp

APP_CPPFLAGS := -std=gnu++0x

APP_CPPFLAGS += -frtti

APP_CPPFLAGS += -fexceptions

APP_CPPFLAGS += -DDEBUG

APP_CPPFLAGS += -std=c++11

NDK_TOOLCHAIN_VERSION := 4.8

LOCAL_C_INCLUDES += ${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.8/include

APP_USE_CPP0X := true

Thanks in advance.

Upvotes: 8

Views: 12295

Answers (3)

Meir Gerenstadt
Meir Gerenstadt

Reputation: 3593

You may try this:

#include <string>
#include <sstream>

#if defined(__ANDROID__)
#define TO_STRING to_stringAndroid

template <typename T>
inline std::string to_stringAndroid(const T& value)
{
    std::ostringstream os ;
    os << value ;
    return os.str() ;
}


#else

#define TO_STRING std::to_string

#endif

Upvotes: 3

hutorny
hutorny

Reputation: 873

I ran into this issue too. to_string is not available in gnu-libstdc++ "out of the box". I searched the sources and found that std::to_string is indeed in the lib (sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_string.h) but opted out by

#if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
     && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))

After adding -D_GLIBCXX_USE_C99 to the build std::to_string is opted in.

Upvotes: 9

thursdaysDove
thursdaysDove

Reputation: 552

Android NDK 9+ comes with llvm-libc++ which has full support for cpp11 features. To enable it, all you have to do is modify these in Application.mk:

APP_CPPFLAGS := -std=c++11

and

APP_STL:=c++_static 

or

APP_STL:=c++_shared

Upvotes: 7

Related Questions