Android Ndk Std::To_String Support

Android ndk std::to_string support

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) ;
}

Error: no member named 'to_string' in namespace 'std'; did you mean 'toString'? Gradle+Cmake

Does it mean CLang does not meet STandarD?

No, it is because minimal std library set in Android NDK by default.

I use gradle build system:

android {
...
defaultConfig {
...
// This block is different from the one you use to link Gradle
// to your CMake build script.
externalNativeBuild {
cmake {
...
// Use the following syntax when passing arguments to variables:
// arguments "-DVAR_NAME=VALUE"
// ------------------- ANSWER -------------------
arguments "-DANDROID_STL=c++_shared"
}
}
}
buildTypes {...}

// Use this block to link Gradle to your CMake build script.
externalNativeBuild {
cmake {...}
}
}

Read these:

https://developer.android.com/ndk/guides/cmake.html#variables

https://developer.android.com/ndk/guides/cpp-support.htm

Android NDK Source Compiled & Build Successfully - But Function 'to_string' could not be resolved in Eclipse IDE

After referring the answer by @Khaled Lakehal, I myself posting this answer for my question.Hope this may help someone.

Followed the below step to make it work:

  1. Update the eclipse version from Luna to latest Mars 2
  2. Imported the existing project from the old version of the eclipse
    using -> import -> Existing Android code into Workspace
  3. Had some problem with the C/C++ project conversion after import. So followed this link to undo the C/C++ project conversion
  4. Converted the project to C/C++ newly.
  5. To remove the error, I referred this link, and selected the "Run with build" only
  6. Close & Reopen the IDE

So now able to use the std::to_string & std::stoll functions.

android NDK complains std::nearbyint is not a member of std

This is part of https://github.com/android-ndk/ndk/issues/82. GNU's libstdc++ is overly broad with their feature guards. We're working on stabilizing the NDK's solution for libc++ so we can just move entirely over to that instead.

Does NDK support C++14?

Bionic is the standard C library. It does not support any C++ std library features let alone C++14.

If you are asking about NDK, then as per the cpp-support page for NDK, LLVM's libc++ is the C++ standard library that has been used by the Android OS since Lollipop and this supports C++17 features.

Sample Image



Related Topics



Leave a reply



Submit