【问题标题】:C++11 std::async in Android NDK does not workAndroid NDK 中的 C++11 std::async 不起作用
【发布时间】:2013-08-11 13:39:07
【问题描述】:

我试图让以下示例代码工作,以了解异步编程是否在 Android NDK 中工作。虽然 NDK 有 STL <future> 被识别为标头,但 std::async 没有被识别没有被识别。我尝试使用的代码如下:

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

此外,所有包含路径都已设置为 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

【问题讨论】:

    标签: android c++11 android-ndk


    【解决方案1】:

    目前,Android NDK 并未包含所有 C++11 功能。来自 NDK r9b 的 Clang 3.3 编译器是 C++11 功能完整的,但是,Android 上的 STLstdlib 不完整。

    要使用 Android 中最新的 C++11 功能集,请使用来自 Android NDK r9b 的 Clang 3.3 编译器。将此行放入您的 Application.mk 文件中:

    NDK_TOOLCHAIN_VERSION := clang
    

    另外,将-std=c++11 开关添加到LOCAL_CPPFLAGS 变量:

    LOCAL_CPPFLAGS += -std=c++11
    

    【讨论】:

    • 我仍然没有得到它......事实上,我什至无法使用 中定义的枚举......这是 Eclipse 或 ndk 或我的库的问题不知道
    • 是NDK的问题。只是等待更新。 Clang 3.3 和新的标准库总有一天会出现。
    • @user2508941 NDK r9 已发布,使用 clang 3.3。
    • @Samveen:而且 r9 仍然没有包含所有功能(主要是 STL 和 stdlib)
    • @SergeyK。更新您对 r9 和 clang 3.3 可用性的回答,而不是评论 clang 3.3 中的 C++11 功能集支持。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多