I am getting "error: no member named 'async' in namespace 'std' " when compiling using MakeFile

When I run command clang++ -Wall -g -std=c++11 main.cpp in terminal the file gets compiled successfully.

% clang++ -Wall -g -std=c++11 main.cpp
% ./a.out                             

But when I try to do the same thing using MakeFile. I get following error.
I don’t know why error occurred when same command is executed in both case.

% make main
c++     main.cpp   -o main
main.cpp:17:5: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
    auto s = std::async(get);
main.cpp:17:19: error: no member named 'async' in namespace 'std'
    auto s = std::async(get);
1 warning and 1 error generated.
make: *** [main] Error 1

My MakeFile content:

main: main.cpp
    clang++ -Wall -g -std=c++11 main.cpp

My main.cpp content:


std::string get() {
    std::string s;
    std::getline(std::cin, s);
    return s;
void put(std::string s) {
    std::cout << s << std::endl;
int main(int argc, char **argv){
    auto s = std::async(get);
    std::thread t(put, s.get());
    return 0;

>Solution :

As you can see when you run make, the compilation command invocation is missing the -std=c++11 option that you use when you’re compiling your code manually.

You can use


to have make automatically add this option when building .o files from .cpp files.

You can also provide the -g and -Wall options the same way.

Leave a Reply