![](/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.