Reputation: 151
I'm currently trying to cross-compile a cross-platform library I have previously developed in order to use it on Android. To do so, I use the arm-linux-androideabi-g++ (4.9) compiler provided by the NDK, and I link the gnu-libstdc++ also present in the NDK.
Unfortunately, the compilation won't succeed due to the use of some C++11 features. Such features are specific methods present in "string.h" like std::to_string or std::stof, which could be replaced easily by other ones if I have to. But I also use more complex ones, like things from "future.h" such as std::future and std::async.
I've located the reason of the compilation error for "string.h", in the file "ndk/sources/cxx-stl/gnu-libstdc++/4.9/bits/basic_string.h", the following statement returning false (_GLIBCXX_USE_C99 isn't defined):
//basic_string.h
#if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
&& !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
//methods I want to use
#endif
From what I understood, these restrictions are induced by the Android Bionic libc.
What options do I have to solve this ?
I already tried to use the CrystaX NDK, but it only solves my "string.h" problem, and I would rather find a more standard solution.
How about using an ARM cross-compiler which isn't specific to Android ?
Thanks.
Upvotes: 2
Views: 786
Reputation: 151
I've finally found a solution to this issue.
First, the use of "future.h" methods is fully supported by the gnu-libstdc++ provided by the android NDK, I just missed some inclusions allowing its usage, my bad.
Next, I've taken a deep look into my library and I've figured out that the only method actually causing compilation errors was std::to_string. So I decided to simply override it with the following :
#if __ANDROID__
namespace std {
#ifndef to_string
inline string to_string(int _Val)
{ // convert int to string
char _Buf[256];
sprintf(_Buf, "%d", _Val);
return (string(_Buf));
}
#endif
}
#endif
I guess that if there is some other unsupported C++11 methods, it's possible to override them as well.
Upvotes: 0