3

我知道这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++11CXXFLAGS无济于事CPPFLAGS
4

1 回答 1

0

看起来你没有编译c++11,添加-std=c++11(或更高版本)到你的编译器命令行或makefile。

于 2020-11-21T07:19:32.117 回答