![](/img/trans.png)
[英]cocos2d-x 3 build_native.py (clean, rebuild, debug build)
[英]Compiling cocos2d-x via build_native.py returns: 'to_string' was not declared in this scope
我正在尝试通过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版本编译该项目。
我还要在这里做什么?
在此线程之后,我决定包括以下内容:
#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
尝试使用atoi代替stoi。 尽管atoi会在错误时返回零,但可用于命令行编译
您可以使用sstream库进行int到str的转换过程,虽然它很长一段时间,但是可以工作:
#include <sstream>
std::stringstream myStringStream ;
myStringStream << myInteger;
myString = myStringStream.str();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.