[英]C++11 std::async in Android NDK does not work
I have tried to get following sample code working to know whether asynchronous programming is working in Android NDK. 我试图获取以下示例代码,以了解异步编程是否在Android NDK中有效。 Though NDK has the STL
<future>
which gets recognized as a header, the std::async
is not getting recognized are not getting recognized. 尽管NDK将STL
<future>
识别为标题,但未获得识别的std::async
未被识别。 The code I tried to use was the following: 我试图使用的代码如下:
#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 the include paths have been set to the specified folder under Properties->Paths and Symbols 此外,所有包含路径都已设置为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
Curently Android NDK does not incorporate all of the C++11 features. 当然,Android NDK并未包含所有C ++ 11功能。 Clang 3.3 compiler from NDK r9b is C++11-feature complete, however,
STL
and stdlib
on Android are not. 来自NDK r9b的Clang 3.3编译器完全是C ++ 11功能,但Android上的
STL
和stdlib
却没有。
To use the most recent C++11
feature set in Android use Clang 3.3 compiler from Android NDK r9b
. 要在Android中使用最新的
C++11
功能集,请使用Android NDK r9b
Clang 3.3编译器。 Put this line into your Application.mk
file: 将此行放入
Application.mk
文件中:
NDK_TOOLCHAIN_VERSION := clang
Also, add -std=c++11
switch to the LOCAL_CPPFLAGS
variable: 另外,添加
-std=c++11
切换到LOCAL_CPPFLAGS
变量:
LOCAL_CPPFLAGS += -std=c++11
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.