【发布时间】: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++11CXXFLAGS和CPPFLAGS也无济于事。
【问题讨论】:
-
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