4

I know that std::async is a C++11 thing but I am pretty sure that my compiler has C++11 support.

#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'
}

and if I use

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

Also g++ --version shows

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

I have gone through the following,

Also,

  • OS: macOS Catalina
  • This code is part of a bigger project (wrapper over TigerVNC) so there is a makefile, but since auto complies without any issues I don't think C++11 is the issue and hence passing -std=c++11 in the CXXFLAGS and CPPFLAGS also doen't help.
Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
coda
  • 2,188
  • 2
  • 22
  • 26
  • 11
    Getting *throws warning warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]* means you are not using C++11. Something is not correct in your makefile or compiler command. Can you post that info? – NathanOliver Nov 20 '20 at 20:56
  • Thanks Nathan, I was missing `std=c++11` at one of the places in the makefile. I can mark your answer has "Answer" if you post it separately :) – coda Nov 21 '20 at 04:02

1 Answers1

1

Looks like you are not compiling with c++11, add -std=c++11 (or later) to your compiler command line or makefile.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175