【问题标题】:error: no member named 'async' in namespace 'std'错误:命名空间“std”中没有名为“async”的成员
【发布时间】:2021-03-04 07:11:09
【问题描述】:

我知道std::async 是 C++11 的东西,但我很确定我的编译器支持 C++11。

#include <future>
using namespace::std;

void functionToRun() {
  // some code
}

int main() {
    auto x = 2; // throws warning warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    std::future<void> metricLoggerFuture = std::async(std::launch::async, functionToRun); // throws error  no member named 'async' in namespace 'std'
}

如果我使用

std::future<void> metricLoggerFuture = async(std::launch::async, functionToRun); // error: use of undeclared identifier 'async'

还有 g++ --version 显示

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

我经历了以下,

还有,

  • 操作系统:macOS Catalina
  • 此代码是一个更大项目的一部分(TigerVNC 的包装器),因此有一个 makefile,但由于 auto 没有任何问题,我认为 C++11 不是问题,因此传入 -std=c++11 CXXFLAGSCPPFLAGS 也无济于事。

【问题讨论】:

  • Getting throws warning warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions] 表示你没有使用 C++11 .您的 makefile 或编译器命令中的某些内容不正确。您可以发布该信息吗?
  • 谢谢 Nathan,我在 makefile 中的某个地方丢失了 std=c++11。如果您单独发布,我可以将您的答案标记为“答案”:)

标签: macos c++11 clang++ stdasync std-future


【解决方案1】:

您似乎没有使用c++11 进行编译,请将-std=c++11(或更高版本)添加到您的编译器命令行或makefile。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-09
    • 2017-02-13
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多