提问人:coda 提问时间:11/21/2020 最后编辑:Florian Weimercoda 更新时间:11/21/2020 访问量:2245
错误:命名空间“std”中没有名为“async”的成员
error: no member named 'async' in namespace 'std'
问:
我知道这是C++11的事情,但我非常确定我的编译器支持C++11。std::async
#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,但由于符合没有任何问题,我认为 C++11 不是问题,因此传入 和 也无济于事。
auto
-std=c++11
CXXFLAGS
CPPFLAGS
答:
1赞
Fantastic Mr Fox
11/21/2020
#1
看起来您没有使用 、add(或更高版本)编译到编译器命令行或 makefile。c++11
-std=c++11
评论
std=c++11