Invalid use of incomplete type in android ndk using c++11 std::async

android, android-ndk, c++, c++11, cygwin

Solution

Android NDK r8e does not have the full run-time library support of `C++11`. You will need to compile your own NDK using some third-party `stdlib` or wait Google to include the `Clang 3.3` in the NDK which is `C++11` feature-complete.

Problem

I tried to use the following function to check whether std::async is supported in android ndk with Eclipse along with cygwin in windows. The function I used is the following Machine: 64bit win 8 with cygwin Android: r8e Eclipse: Juno 4.2.1 ADT: 22.0.1 ``` struct Foo { Foo() : data(0) {} void sum(int i) { data +=i;} int data; }; int main() { Foo foo; auto f = std::async(&Foo::sum, &foo, 42); f.get(); std::cout << foo.data << "\n"; } ``` I get the following error: Description Resource Path Location Type invalid use of incomplete type 'std::__async_sfinae_helper::type {aka struct std::future}' Sample.cpp /Cli13/jni line 63 C/C++ Problem Note: I have set the _GLIBCXX_HAS_GTHREADS and also the GXX_EXPERIMENTAL_CXX0X along with the ATOMIC_INT_LOCK_FREE... By default the ndk uses 4.6 toolchain. I had to include the gnu-libstd++ for 4.7 manually in Properties-> C/C++ -> Includes. Is there any work around to make the std::async working??? Thank You.

Original source