I'm using android NDK r9d and toolchain 4.8 but I'm not able to use std::to_string function, compiler throws this error:
error: 'to_string' is not a member of 'std'
Is this function not supported on android ndk? I try APP_CPPFLAGS := -std=c++11
with no luck.
You can try LOCAL_CFLAGS := -std=c++11
, but note that not all C++11 APIs are available with the NDK's gnustl. Full C++14 support is available with libc++ (APP_STL := c++_shared
).
The alternative is to implement it yourself.
#include <string>
#include <sstream>
template <typename T>
std::string to_string(T value)
{
std::ostringstream os ;
os << value ;
return os.str() ;
}
int main()
{
std::string perfect = to_string(5) ;
}
With NDK r9+ you can use llvm-libc++ which offers full support for cpp11.
In your Application.mk you have to add:
APP_STL:=c++_static
or
APP_STL:=c++_shared
If you looking for solution for Gradle build system. Look at this answer.
Add the string
arguments "-DANDROID_STL=c++_shared"
in your build.gradle
. Like
android {
...
defaultConfig {
...
externalNativeBuild {
cmake {
...
arguments "-DANDROID_STL=c++_shared"
}
}
}
...
}
If you're looking for a solution for the Experimental Gradle plugin, this worked for me...
Tested with com.android.tools.build:gradle-experimental:0.9.1
model {
...
android {
...
ndk {
...
stl = "c++_shared"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With