Question

I am trying to build a cocos2d-x 3.0 (stable) project for Android via the build_native.py script but it hangs when a class is using the std::to_string (or the std::stoi) function. Building the project under Xcode gives no problem at all, it's just the command line compilation that fails.

I am already importing <string> in all the classes that make use of those functions, but with no success. I also modified the Application.mk file like this:

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

adding the -std=c++11 flag to make sure the project is compiled using the C++11 version.

Is there anything else I should do here?

More

Following this thread I decided to include this:

#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

in my headers, since I'm just using to_string with integer inputs. It is not a good solution, but works fine ... but then the compiler hangs when it finds the stoi function, again.

Était-ce utile?

La solution

I ended up using this piece of code:

#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

Autres conseils

Try using atoi instead of stoi. Altough atoi returns zero on error, but it works with command line compilation

you can do int to str conversion process by using sstream library, its some long but it works :

#include <sstream>
std::stringstream myStringStream ; 
myStringStream << myInteger;
myString = myStringStream.str();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top