GCC std::thread not found in namespace std
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.
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
.
std::thread is not a member of namespace std using Eclipse Kepler MinGW
Plain MinGW cannot support std::thread
. You will need to use a MinGW-w64 toolchain (such as those shipped with Qt 5) that has "posix" threading enabled, so that libstdc++ exposes the <thread>
, <mutex>
and <future>
functionality.
You can find an installer here, but you can also try just replacing the whole mingw
toolchain root folder with one of these packages. You can choose 32- or 64-bit, remember to select threads-posix
if you want to play with std::thread
and friends. No special compiler options other than the ones you already have are needed. I do suggest using -std=c++11
if you don't need GCC 4.6 compatibility.
Error: 'thread' in namespace 'std' does not name a type
The version of GCC that CodeBlocks ships with doesn't support threads (or at least it was the case last time I checked). You'll have to install a better compiler, and configure CB to use it.
You can get a fresh version of GCC from MSYS2. Or you can install one of the numerous MinGW-w64 distributions.
Why doesn't my compiler recognize #include thread (c++)?
MinGW-w64 by default comes with native (Win32) instead of POSIX threads support, and unfortunately there is currently no Win32 gthreads implementation (the threading subsystem of libstdc++), hence no threading functionality in GCC.
You need to switch from x86_64-w64-mingw32-g++-win32
to x86_64-w64-mingw32-g++-posix
package to get std::thread
working in MinGW-w64.
The question mingw-w64 threads: posix vs win32 discusses this issue in more detail.
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/
Related Topics
Std::Variant' VS. Inheritance VS. Other Ways (Performance)
Remove Duplicates from a List<Int>
Other's Library #Define Naming Conflict
Can't Use Structure in Global Scope
G++ Linker: Force Static Linking If Static Library Exists
Cin >> Fails with Bigger Numbers But Works with Smaller Ones
Calling Constructors in C++ Without New
C++ Abstract Class: Constructor Yes or No
Finding Memory Leaks in a C++ Application with Visual Studio
Why Are Pointers to a Reference Illegal in C++
Workaround for Error C2536: Cannot Specify Explicit Initializer for Arrays in Visual Studio 2013
Move Element from Boost Multi_Index Array
C++ Return Value, Reference, Const Reference
How to Know the Right Max Size of Vector? Max_Size()? But No