c++ - 通过 build_native.py 编译 cocos2d-x 返回 : 'to_string' was not declared in this scope

标签 c++ c++11 cocos2d-x cocos2d-x-3.0

我正在尝试通过 build_native.py 为 Android 构建一个 cocos2d-x 3.0(稳定)项目脚本,但当类使用 std::to_string 时它会挂起(或 std::stoi )函数。在 Xcode 下构建项目完全没有问题,只是命令行编译失败。

我已经在导入 <string>在所有使用这些功能的类中,但没有成功。我还修改了 Application.mk像这样的文件:

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

添加 -std=c++11标志以确保项目是使用 C++11 版本编译的。

还有什么我应该做的吗?

更多

正在关注 this thread我决定包括这个:

#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
string to_string(int t) {
    ostringstream os;
    os << t;
    return os.str();
}
#endif

在我的标题中,因为我只是使用 to_string与整数输入。这不是一个好的解决方案,但工作正常......但是编译器在找到 stoi 时挂起功能,再次。

最佳答案

我最终使用了这段代码:

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
string to_string(int t) {
  ostringstream os;
  os << t;
  return os.str();
}

int stoi(const string myString) {
  return atoi(myString.c_str());
}
#endif

关于c++ - 通过 build_native.py 编译 cocos2d-x 返回 : 'to_string' was not declared in this scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23682148/

相关文章:

c++ - sprite在cocos2d-x中无法移动

c++ - 如何从 QLineEdit 连接焦点事件?

C++11:使用右值引用实现装饰器的最佳方式

c++ - cocos2d-x中如何设置图层的背景颜色?

c++ - 将文字分配给 std::u16string 或 std::u32string

c++ - 如何转换C++11中忽略参数的函数?

android - 用于游戏开发的 cocos2d-iphone 或 cocos2d-x?

c++ - gcc C++14 与 msvc++ 2015 中的级联宏

c++ - 是否可以使用 begin() 和 end() 创建 std::array?

c++ - "for(;;)"的用途是什么