Mingw Error: 'Thread' Is Not a Member of 'Std'

MinGW error: ‘thread’ is not a member of ‘std’

This error means that the STL you are using does not contain all the features of C++11.

To access C++11 threads in Windows, you will need a build of Mingw with posix-threads. Here you can find Mingw-Builds v4.8.1: http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.1/64-bit/threads-posix/sjlj/

thread is not a member of std c++

The code you present never does #include <thread>. So how is the compiler supposed to know what a std::thread is?

Fix your problem by adding #include <thread> to the top of your file.

Also make sure you use a compiler that actually supports C++11 (or later) and std::thread.

thread' is not a member of 'std' in Eclipse Neon with MinGW 6.3 GCC on Windows

With the advice of sbabbi, "Mingw32 does not support std::thread. ...You can switch to mingw64+winpthread (but TLS is utterly broken in that config) or use Boost.thread.", I decided to set up Boost and use that instead. I also switched to cygwin because it has the Boost libraries built in and I switched to Netbeans because installing Boost in eclipse was proving itself to be unnecessarily difficult.

Why do I get this error: 'thread' is not a member of 'std'?

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.

std::thread works in cygwin but not in MinGw

MinGW-w64 (or rather GCC on windows) needs to be compiled with posix thread support if you want to use std::thread, presumably you downloaded a build with native windows threads.

Check out the mingw-builds folders targeting 64 bit or 32 bit and pick a version with posix threads. You'll also need to choose the exception handling method, if you don't have a reason to choose otherwise then stick with the GCC defaults of seh for 64 bit and dwarf for 32.



Related Topics



Leave a reply



Submit