std::thread error (thread not member of std)

I compiled & installed gcc4.4 using macports.

When I try to compile using -> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp...:

 #include <thread>
  std::thread t(handle);

The compiler returns:

 cserver.cpp: In member function 'int CServer::run()':
 cserver.cpp:48: error: 'thread' is not a member of 'std'
 cserver.cpp:48: error: expected ';' before 't'
 cserver.cpp:49: error: 't' was not declared in this scope

But std::cout <<... compiles fine..

Can anyone help me?


gcc does not fully support std::thread yet:

Use boost::thread in the meantime.


Although the following compiled and ran fine for me with gcc 4.4.3:

#include <thread>
#include <iostream>

struct F
  void operator() () const
    std::cout<<"Printing from another thread"<<std::endl;

int main()
  F f;
  std::thread t(f);

  return 0;

Compiled with

g++ -Wall -g -std=c++0x -pthread main.cpp

Output of a.out:

Printing from another thread

Can you provide the full code? Maybe there's some obscure issue lurking in those ...s?

Drop -ansi, it means -std=c++98, which you obviously don't want. It also causes macro __STRICT_ANSI__ to be defined and this may change the behavior of the headers, e.g. by disabling C++0x support.

I had the same issue on windows using MinGW. I found wrapper classes for in on github mingw-std-threads Including mingw.mutex.h, mingw.thread.h files to global MinGW directory fixed this issue. All I had to do is to include header file and my code stayed the same

#include "mingw.thread.h"

std::thread t(handle);

Well I tried on Ubuntu with GCC 4.4.1 and it works like a charm. The problem is Mac OS X specific, now only need to find out why...

Are you sure you're pulling in the right compiler? Do you have gcc_select?

Need Your Help

How do i make a cell using variables? using VB script in Excel 2007

vbscript excel-2007

I am working on a project which requires me check for the last used row in the spreadsheet and then extract data from a range of cells from another spreadsheet after this last used row in a cell (i...

dataTables jquery - how to add sorting image/icon?

javascript jquery sorting jquery-datatables

I use dataTables jquery. I want to add sorting image to the columns and the image shd also change on sorting.That is, if the image is showing descending icon and on clicking it should change to