C ++ 11的std ::异步于Android的NDK不工作 [英] C++11 std::async in Android NDK does not work

查看:525
本文介绍了C ++ 11的std ::异步于Android的NDK不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让下面的示例code工作要知道异步编程工作是否在Android的NDK。虽然NDK有STL <未来> 这被认为是一个头球攻门,的std ::异步是没有得到公认的是没有得到认可。在code我试图用是以下内容:

 的#include<未来>
#包括<的iostream>

结构美孚
{
  美孚():数据(0){}
  无效总和(int i)以{数据+ =我;}
  int数据;
};

诠释的main()
{
    富富;
    汽车F =的std ::异步(安培;富::总和,和放大器; FOO,42);
    f.get();
    性病::法院<< foo.data<< \ N的;
}
 

另外所有的包括路径已被设置为在属性 - >路径和符号

指定的文件夹

 错误
描述资源路径位置类型
无效的使用不完全型'的std :: __ async_sfinae_helper<无效(美孚:: *)(INT),无效(美孚:: *)(INT),富*,INT和GT; ::类型{又名结构的std ::未来<无效:GT ;}'将sample.cpp / Project12 / JNI行50 C / C ++问题

描述资源路径位置类型
声明'的std :: __ async_sfinae_helper<无效(美孚:: *)(INT),无效(美孚:: *)(INT),富*,INT和GT; ::类型{又名结构的std ::未来<无效>} Project12线111,外部位置:D:\ Android的NDK-R8E  - 窗口 -  x86_64的\ Android的NDK-R8E \来源\ CXX-STL \ GNU-的libstdc ++ \ 4.6 \包括\未来的C / C ++问题
 

解决方案

Curently的Andr​​oid NDK不把所有的C ++ 11的特性。锵3.3编译器NDK R9B是C ++ 11的功能齐全,但是, STL STDLIB 在Android上不

要使用最新的 C ++ 11 的功能在Android的设置使用锵3.3编译器的Andr​​oid NDK R9B 。把此行到您的 Application.mk 文件:

  NDK_TOOLCHAIN​​_VERSION:=铛
 

此外,添加 -std = C ++ 11 切换到 LOCAL_CPPFLAGS 变量:

  LOCAL_CPPFLAGS + = -std = C + + 11
 

I have tried to get following sample code working to know whether asynchronous programming is working in 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. 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

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. Clang 3.3 compiler from NDK r9b is C++11-feature complete, however, STL and stdlib on Android are not.

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

NDK_TOOLCHAIN_VERSION := clang

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

LOCAL_CPPFLAGS += -std=c++11

这篇关于C ++ 11的std ::异步于Android的NDK不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆