现象¶

cocos2d-x 2.2.6 项目的源码中使用了 std::to_string() 方法,使用 NDK r9d 编译的时候,报如下错误:

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

Application.mk 文件的部分内容如下:

APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION := 4.8
APP_CPPFLAGS := -frtti -std=c++11 -fexceptions -Wno-error=format-security -Wno-literal-suffix -Wno-deprecated-declarations -fsigned-char -Os $(CPPFLAGS)

换用 NDK 10e ,错误依然。

快速解决¶

想快速解决这个问题,可以自己写一个 std::to_string() 替换标准库中的。

首先写一个 stdtostring.h 文件:

#ifndef STDTOSTRING_H
#define STDTOSTRING_H
#include <string>
#include <sstream>using namespace std;
namespace std
{template < typename T > std::string to_string( const T& n ){std::ostringstream stm ;stm << n ;return stm.str() ;}
}
#endif

然后在需要使用 std::to_stirng() 方法的源文件中包含它:

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include "stdtostring.h"
#endif

追根溯源¶

Why gnustl_static 中介绍了采用 c++_static 和 clang 编译器来实现std::to_string() 支持,于是我尝试了下:

# APP_STL := gnustl_static
# NDK_TOOLCHAIN_VERSION := 4.8
APP_STL := c++_static
NDK_TOOLCHAIN_VERSION := clang

根据 C++ Library Support 的说明, c++_static 对应的是 The LLVM libc++ runtime (static) ,因此应该采用 clang 的工具链进行编译。

结果是: std::to_string() 编译正常,但出现下面的错误:

In file included from src/Utilities.cpp:1:0:
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1498:46: error: expected unqualified-id before 'float'
inline _LIBCPP_INLINE_VISIBILITY float       remainder(float __x, float __y) _NOEXCEPT             {return remainderf(__x, __y);}^
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1498:46: error: expected ')' before 'float'
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1499:46: error: expected unqualified-id before 'long'
inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __x, long double __y) _NOEXCEPT {return remainderl(__x, __y);}^
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1499:46: error: expected ')' before 'long'
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1509:1: error: expected ')' before '__x'
remainder(_A1 __x, _A2 __y) _NOEXCEPT
^
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1559:46: error: expected unqualified-id before 'float'
inline _LIBCPP_INLINE_VISIBILITY float       round(float __x) _NOEXCEPT       {return roundf(__x);}^
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1559:46: error: expected ')' before 'float'
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1560:46: error: expected unqualified-id before 'long'
inline _LIBCPP_INLINE_VISIBILITY long double round(long double __x) _NOEXCEPT {return roundl(__x);}^
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1560:46: error: expected ')' before 'long'
android-ndk-r9d/sources/cxx-stl/llvm-libc++/libcxx/include/cmath:1565:1: error: expected ')' before '__x'
round(_A1 __x) _NOEXCEPT {return round((double)__x);}

minggo 在 Cocos can’t compile Android with APP_STL := c++_static 中提到:

A prebuilt version can only support one type of c++ lib. Did you mean we should provide two kinds of prebuilt libcocos2d that using two different c++ libs?

I don’t know if cocos2d can compile with c++_static or not. I don’t remember if there is a good reason to choose one instead of other one. But cocos2d-x uses gnustl_static from very early version, so we know it works well. You can replace it with c++_static if you like, but it is not fully tested.

因此我怀疑在 cocos2d-x 的旧版本中, c++_static 是没有经过完整测试的。

也有人说 在新版本(>3.7)中, gnustl_static 会导致 lambda 和std::to_string 不能使用,已经切换到使用 c++_static 和 clange 组合。

I never made it to work with gnustl_static and gcc with all the c++11 features. I was getting crashes in simple lambdas, as mentioned std::to_string was missing and much more, so i’ve switched to c++_static and clang long time ago.

本文转自:http://www.tuicool.com/articles/RBBjMz

转载于:https://www.cnblogs.com/Anzhongliu/p/6091789.html

error: ‘to_string’ is not a member of ‘std’———已解决相关推荐

  1. caffe中在某一层获得迭代次数的方法以及caffe编译时报错 error: ‘to_string‘ is not a member of ‘std‘解决方法

    caffe中在某一层获得迭代次数的方法以及caffe编译时报错 error: 'to_string' is not a member of 'std'解决方法 参考文章: (1)caffe中在某一层获 ...

  2. g++报错解决:error: ‘setw’ is not a member of ‘std’

    下午在用g++编译的时候报错如下: zhang@debian:~/CuteCompiler$ g++ -std=c++11 test.cpp -o test test.cpp: In function ...

  3. error::make_unique is not a member of ‘std’

    原因: CMakeLists.txt中设置 set(CMAKE_CXX_STANDARD 11) 此时,在编译使用 std::make _ unique 创建 std:: unique_ptr智能指针 ...

  4. error: ‘integer_sequence’ is not a member of ‘std’

    本人在编译CAMODOCAL工程时遇到了该错误: /usr/local/include/ceres/internal/integer_sequence_algorithm.h:64:21: error ...

  5. insmod error could not insert module ... invalid module format [已解决]

    自己写了个usb test driver,Makefile相关行如下 KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd)d ...

  6. 连接服务器时遇到报错:ERROR:ORA-12638: 身份证明检索失败(问题已解决)

    在学校学习数据库相关知识的时候,因为在安装Oracle21c然后乱动了各种七七八八的设置.导致用命令提示窗口用校园网连接学校的数据库的时候报错身份证明检索失败.如下: 首先在任务栏搜索注册表编辑器,然 ...

  7. Tesseract在安装过程中出现Download error Status of equ: Send Request Error. Click OK to continue!!!已解决#附安装包

    安装时会出现 查了资料后总结出: (1)首先要肯定,这些安装包没有错误 (2)然后,出错的地方是"send requests erro",请求出错的原因应该是,墙的问题,,请求失败 ...

  8. ‘make_unique’ is not a member of ‘std’

    ../UniqueStrTest/main.cpp: In function 'int main(int, char**)': ../UniqueStrTest/main.cpp:35:25: err ...

  9. 【已解决】error: ‘xxx’ is not a member of ‘xxx’

    一.问题描述 在改动openvslam源码时,遇到如下问题: error: 'keyframe' is not a member of 'openvslam::data' 改动为在system.h中加 ...

最新文章

  1. Java fork join ForkJoinPool 用法例子
  2. IT创业光技术好,谋略定位不好,你很可能会死得很惨,丢钱、丢客户、丢成果、丢商机、丢思路...
  3. 6 redhat 查看rtc时间_修改linux系统时间、rtc时间以及时间同步
  4. 四、MyBatis-映射文件
  5. Virtualbox安装增强工具失败
  6. 蓝桥杯JAVA---2013---B----世纪末的星期
  7. python分割字符串输出_python字符串分割
  8. 怎么更改wifi频段_wifi信号差?网速慢?这样做不浪费每一兆宽带
  9. 在函数内对带副作用的运算符 rand 的使用无效。_如何成体系掌握Excel函数(一)...
  10. JSP项目155套-开发专题-大作业设计-毕业设计【建议在校生收藏】(保持更新)
  11. QuickTime 介绍 下载 安装(win7及以上版本)
  12. 关于fcitx无法切换输入法的问题解决
  13. 批处理之批量修改文件扩展名
  14. 宏病毒组(四)|病毒注释软件介绍
  15. 2017年最全的电子杂志制作教程都在这里了
  16. 计算机辅助导航技术口腔外科,计算机辅助导航技术在口腔种植手术中的应用.pdf...
  17. 系统发育树的美化(iTOL)
  18. 详解设计模式:装饰器模式
  19. java毕业设计在线水果超市Mybatis+系统+数据库+调试部署
  20. bert4keras中预训练代码阅读

热门文章

  1. 2018成都初二计算机会考时间,2018年四川学业水平考试时间及科目
  2. 计算机桌面颜色如何设置标准,电脑调整桌面颜色设置_电脑桌面颜色设置
  3. java字数统计_java统计字数
  4. homeassistant树莓派cpu_集成ESP8266的WiFi RGB灯泡接入Home Assistant
  5. JZOJ 3660. 【SHTSC2014】信号增幅仪
  6. c语言作业指导1,C语言程序设计实验与习题指导
  7. python基础语法测评_Python基础语法知识点汇集
  8. 个人常用word技巧----平时编辑word能快不少~
  9. BZOJ-几道比较有趣的题目
  10. [codevs 1904] 最小路径覆盖问题