代码如下
#include <future>
#include <exception>
#include <typeinfo>
#include <stdio.h>
using namespace std;
void f()
{
printf("exec f\n");
}
int TestCpp11()
{
std::this_thread::sleep_for(std::chrono::seconds(10));
auto fu = async(launch::async, f);
return 0;
}
Application.mk中
APP_ABI := armeabi
怎么都编译不过,提示
jni/main.cpp: In function 'int TestCpp11()':
jni/main.cpp:17:34: error: invalid use of incomplete type 'class std::future<void>'
auto fu = async(launch::async, f);
^
In file included from jni/main.cpp:1:0:
D:/android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.9/include/future:114:11: error: declaration of 'class std::future<void>'
class future;
把APP_ABI 的值改为armeabi-v7a后编译通过,c++11需要gcc4.7以上才支持,armeabi的gcc版本应该是比较低不支持导致编译失败。