macos - 错误:命名空间“std”中没有名为“async”的成员
问题描述
我知道这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
也CXXFLAGS
无济于事CPPFLAGS
。
解决方案
看起来你没有编译c++11
,添加-std=c++11
(或更高版本)到你的编译器命令行或makefile。
推荐阅读
- javascript - 无法读取未定义的属性“rollupVersion”或如何使用 rollup 和 babel 设置 gulp
- javascript - 通过jquery调用对象函数
- excel - 在 Excel VBA 中将对象添加到集合时遇到问题
- react-native - 需要按 flatlist child 2/3 秒才能实际移动到链接
- webhooks - 是否有任何 webhook 可用于了解用户是否可以使用 google Filt 新数据?
- jenkins - 詹金斯管道蝙蝠多行
- object - Flutter中如何存储一个可以被其他页面访问的对象
- azure - pod 没有在 kubernetes 中创建,但存在部署?
- java - Java SDK AWS EMR 给出 Failed to download 错误
- php - 无法比较mysql和php中的时间