C ++ 11 std :: async in Android NDK not working

I tried to get the following code sample working to find out if asynchronous programming works in Android NDK. Although the NDK has an STL <future> that is recognized as a header, std::async not recognized, not recognized. The code I tried to use was as follows:

 #include <future> #include <iostream> 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"; } 

Also, all included paths were installed in the specified folder under "Properties-> Paths and Symbols"

 Errors Description Resource Path Location Type invalid use of incomplete type 'std::__async_sfinae_helper<void (Foo::*)(int), void (Foo::*)(int), Foo*, int>::type {aka struct std::future<void>}' Sample.cpp /Project12/jni line 50 C/C++ Problem Description Resource Path Location Type declaration of 'std::__async_sfinae_helper<void (Foo::*)(int), void (Foo::*)(int), Foo*, int>::type {aka struct std::future<void>}' Project12 line 111, external location: D:\android-ndk-r8e-windows-x86_64\android-ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.6\include\future C/C++ Problem 
+6
source share
1 answer

At the same time, Android NDK does not include all the features of C ++ 11. The Clang 3.3 compiler from NDK r9b is a fully functional version of C ++ 11, however, there is no STL and stdlib on Android.

To use the latest C++11 feature set in Android, use the Clang 3.3 compiler from the Android NDK r9b . Put this line in your Application.mk file:

 NDK_TOOLCHAIN_VERSION := clang 

Also, add -std=c++11 to the LOCAL_CPPFLAGS variable:

 LOCAL_CPPFLAGS += -std=c++11 
+9
source

Source: https://habr.com/ru/post/949321/


All Articles