Error compiling gcc 4.6.1 C ++ 0x stream code on MacOSX Lion

When compiling the following code:

#include <iostream>
#include <thread>

using namespace std;

void hello()
{
        cout << "Hello World!" << endl;
}

int main()
{
        cout << "starting" << endl;
        thread t(hello);
        t.join();
        cout << "ending" << endl;
        return 0;
}

using:

$ g++-4.6.1 -std=c++0x -pthread threading.cpp

I get the following error:

threading.cc: In functionint main()’:
threading.cc:13:2: error: ‘threadwas not declared in this scope
threading.cc:13:9: error: expected ‘;’ beforetthreading.cc:14:2: error: ‘twas not declared in this scope

This is on MacOSX Lion with custom gcc 4.6.1. All other C ++ 0x functions that are valid for gcc 4.6 work like a charm. Is this a specific MacOSX error?

+5
source share
2 answers

See http://gcc.gnu.org/PR50196 - Mac OS X does not support some parts of the pthreads that we rely on. Building the latest version will not help, but it can be fixed for GCC 4.7

+3
source

std::thread ( ++ 11) , gcc 4.6.1. , MacOSX .

Just:: Thread ++ 11 32- MacOSX gcc 4.5, gcc 4.6 .

+4

All Articles