16

I am using GCC 4.5.0 with the Eclipse IDE (if that matters) on Windows via MinGW.

I'm using the -std=c++0x flag.

I find that _GLIBCXX_HAS_GTHREADS still isn't defined, so thread for me still isn't a member of namespace std. -- or perhaps it is something else.

What does one do to get C++11 threading support with GCC?

P.S. It doesn't recognize the -pthread flag. I read in a question elsewhere on this site that this works.

Edit: Stupid me: pthread is a library, not an option. It's installed, gcc can find the header, but still no cigar.

Xeo
  • 129,499
  • 52
  • 291
  • 397
defube
  • 2,395
  • 1
  • 22
  • 34

5 Answers5

11

Works fine on Linux (g++ -std=c++0x -lpthread with no additional defines).

However, this thread on Cygwin mailing list suggests that, at least as of 4.4, _GLIBCXX_HAS_GTHREADS was disabled by an autoconf test when building libstdc++ because pthread implementation of cygwin is missing pthread_mutex_timedlock. Perhaps MinGW has the same problem.

Also, this thread on comp.lang.c++.moderated says the same thing. Not supported by the library.

Cubbi
  • 46,567
  • 13
  • 103
  • 169
4

The native Windows builds of gcc do not support the new C++0x/C++11 thread library.

The (commercial) Just::Thread library adds support to the TDM port of gcc 4.5.2 for Windows, as well as MSVC.

Anthony Williams
  • 66,628
  • 14
  • 133
  • 155
3

There is already a lightweight header-only library that implements std::thread and sync primitives in pure win32 API: https://github.com/meganz/mingw-std-threads

IT should work with any version of MinGW that has proper C++11 support.

Alexander Vassilev
  • 1,399
  • 13
  • 23
3

What does one do to get C++0x threading support with GCC?

Use Boost? Seriously http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html claims threads aren't complete even in mainline head so it isn't going to be in any current release.

stonemetal
  • 6,111
  • 23
  • 25
  • Yes, I know about boost and I don't mind using it. I also know that gcc support for C++0x is currently experimental. I was just curious as to why it didn't work with mine when it worked with apparently older versions (which I have tried, and still end up getting the same message). – defube Aug 05 '10 at 13:56
3

Use this builts of mingw: http://code.google.com/p/mingw-builds/downloads/list

niXman
  • 1,698
  • 3
  • 16
  • 40