1

I'm using Code::Blocks 13.12 with TDM-GCC (version 4.7.1, 32 bit). When I try to use the thread class, I get the following error: 'thread' is not a member of 'std'

I was sure to #include <thread>. I enabled the compiler flag -std=c++11 to tell the compiler to conform to the C++11 standard.

I thought maybe my version of GCC wasn't new enough, so I installed TDM-GCC 4.8.1; when I use its compiler, I don't have this problem. However, I then read that GCC versions as low as 4.4 support the C++11 thread class, which means the original version of GCC I had (4.7.1) was already up-to-date enough. What was the problem?

Cerran
  • 1,817
  • 2
  • 19
  • 30

1 Answers1

2

MinGW (which is included in TDM-GCC) comes with one of two APIs for threads: either winpthreads (based on the POSIX threads API, pthreads) or the Win32 thread API. If you have a version with the Win32 thread API, std::thread is disabled. TDM-GCC 4.7.1 uses the Win32 thread API, while TDM-GCC 4.8.1 and later come with winpthreads. That's why the compiler succeeded in one case but not the other.

This leads to 2 possible solutions for the 'thread' is not a member of 'std' problem:

  • Install a version of TDM-GCC that uses winpthreads (either standalone or with Code::Blocks). This means 4.8.1 or later.
  • Use the MinGW installer, which lets you choose which thread API to install. It also lets you choose what version of MinGW (which nowadays corresponds to the version of GCC included) to install, so you can even choose an older version such as 4.7.3, which is more stable than 4.8.1.
Community
  • 1
  • 1
Cerran
  • 1,817
  • 2
  • 19
  • 30
  • Does this affect MinGW64? I can't seem to find anything on that site indicating they haven't fixed this. – Mgetz Jan 30 '14 at 15:55
  • @Mgetz I can't give you a definitive answer, but I believe my answer applies to MinGW 32-bit and 64-bit. No matter which version (4.7.x or 4.8.x) and architecture ("x32" or "x64") I choose in the latest MinGW-builds installer, it still gives me the option of choosing either thread API. I don't know what site you're referring to or what "this" means in "haven't fixed this", though. – Cerran Jan 30 '14 at 16:13