How do I get the new C++ threading support on Mac

2019-03-16 07:15发布

问题:

I just want to compile the following program on Mac OSX 10.8 using Apple clang version 4.1 (tags/Apple/clang-421.11.66):

#include <thread>

using namespace std;

int main() {

    cout << "Hello world";

}

But I get:

../src/FirstCAgain.cpp:13:10: fatal error: 'thread' file not found
#include <thread>

I enabled c++11 support and I'm using the Eclipse C/C++ Development Tooling.

The question is: How do I get the new C++ threading support on Mac OS X ?

回答1:

You need to use the new libc++, which isn't the default:

clang++ -stdlib=libc++ threadtest.cpp 

(Of course you also need to include iostream, but I assume that wasn't you confusion.)