我正在尝试通过 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/