9

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 ?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
rogergl
  • 3,501
  • 2
  • 30
  • 49
  • This is a dup of many many questions, Apple only ship an ancient GCC so its library doesn't have C++11 support, you need to use the alternative libc++ library for C++11 features, see http://stackoverflow.com/a/14150421/981959, or install a newer GCC – Jonathan Wakely Jan 06 '13 at 14:59

1 Answers1

12

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.)

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Hi thanks that seems to work. Now I get "std::__1::locale::use_facet(std::__1::locale::id&) const" when linking but that seems to be a problem of my CDT setup. – rogergl Jan 06 '13 at 08:36
  • 2
    fyi, here nearly 3 years later, worth noting that it is the default now – johnbakers Oct 31 '15 at 20:43