proj.android/build_native.sh -> 'to_string' is not a member of 'std'

  1. [error]
    $ /Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android/build_native.sh
    The Selected NDK toolchain version was 4.8 !
    NDK_ROOT = /Users/yy/Documents/Android/android-ndk-r9
    COCOS2DX_ROOT = /Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android/…/…/…
    APP_ROOT = /Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android/…
    APP_ANDROID_ROOT = /Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android
    Using prebuilt externals
    Android NDK: WARNING: APP_PLATFORM android-18 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml
    Android NDK: WARNING:/Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android/…/…/…/cocos2dx/Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries
    make: Entering directory `/Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android’
    Compile*+ thumb : cocos2dcpp_shared <= GameRank.cpp
    jni/…/…/Classes/Game/MainScene/GameRankLayer/GameRank.cpp: In member function ‘std::string GameRank::get_md5(int)’:
    jni/…/…/Classes/Game/MainScene/GameRankLayer/GameRank.cpp:221:23: error: ‘to_string’ is not a member of ‘std’
    std::string str = std::to_string;
    ^
    make: * Error 1
    make: Leaving directory `/Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android’
    # gcc version
    $ gcc —version
    Configured with: —prefix=/Applications/Xcode.app/Contents/Developer/usr —with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c**/4.2.1
    Apple LLVM version 5.0
    Target: x86_64-apple-darwin13.0.0
    Thread model: posix
    # i update gcc/g*+ to 4.8.2, have this problem too

[[
[android-ndk] std:string c11 operations not available?
http://grokbase.com/t/gg/android-ndk/133m4ptjed/std-string-c-11-operations-not-available
Same problem with ndk r9, g
4.8 toolchain.

maybe this problem is in android-ndk, can not be fixed now.
]]

any one help me?
i update gcc to 4.8.2, have this problem , i find g++ std=c++11 tmp.cppo tmp, but maybe change ndk.sh file?

Did you use c++ 11 feature? If so, you should checkout the content of Application.mk. Application.mk should look like this

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=1 -std=c++11 -Wno-literal-suffix -fsigned-char

PS: Android building uses the gcc under NDK_ROOT, so it is meaningless to paste the gcc version of Xcode used

  • Application.mk in cocos3.0 alpha:
    APP_STL := gnustl_static
    APP_CPPFLAGS := frttiDCC_ENABLE_CHIPMUNK_INTEGRATION=1 DCOCOS2D_DEBUG=1std=c11
    then i change to:
    APP_STL := gnustl_static
    APP_CPPFLAGS := frttiDCOCOS2D_DEBUG=1 -std=c
    11 Wno-literal-suffixfsigned-char

use command to build:
yy$ /Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android/build_native.sh

jni/…/…/Classes/Game/MainScene/GameRankLayer/GameRank.cpp:224:23: error: ‘to_string’ is not a member of ‘std’
std::string str = std::to_string(score); // c++11 在android编译不过去
^
make: **** Error 1
make: Leaving directory `/Users/yy/Documents/cocos2d-x-3.0alpha0-pre/projects/xx/proj.android’
** PS: Android building uses the gcc under NDK_ROOT, so it is meaningless to paste the gcc version of Xcode used —
i don’t know how to change gcc under NDK_ROOT to fix it?

Have you tried samples shift by engine?

Minggo Zhang wrote:

Have you tried samples shift by engine?

what do you mean?

Minggo Zhang wrote:

Have you tried samples shift by engine?

what do you mean?

Minggo Zhang wrote:

Have you tried samples shift by engine?

i try to build samples and the project before, i don’t add std::to_string, build to android is ok.

std::string tempName;
// std::to_string is not supported on android, using std::stringstream instead.
std::stringstream ss;
ss << size;
tempName.append(ss.str());
1 Like

@zhangxm

cocos2d-x-3.0alpha0-pre/samples/Cpp/TestCpp/proj.android

…/…/…/…/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.cpp:37:21: error: ‘to_string’ is not a member of ‘std’
std::string a = std::to_string(1);
^
make: *** [obj/local/armeabi/objs/cocos_testcpp_common/Classes/AccelerometerTest/AccelerometerTest.o] Error 1

I used this when I ran into the same problem…

#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
template<typename T>
string to_string(const T& t) {
	ostringstream os;
	os << t;
	return os.str();
}
#endif
2 Likes

Encountered issue on 2.2.1 w/ r9c (gcc 4.8). Everything else I’m using in C++11 works fine. Just using the old method (with stringstreams) for now…

@IslandPlaya wrote:

I used this when I ran into the same problem…

#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
template\<typename T\>
string to_string(const T& t) {
	ostringstream os;
	os << t;
	return os.str();
}
#endif

Thanks – getting this issue too with C++11 enabled on Android.