Reputation: 25
I am trying to compile the following program on a 64 bit Windows 7 machine with cygwin installed and the gcc compiler updated to 4.7.3:
#include <vector>
#include <thread>
#include <mutex>
using namespace std;
std::mutex flemutex;
std::mutex arrmutex;
main() {
thread t;
}
On compiling with the following command:
gcc -std=c++11 -o file.o -c file.cpp
I get the following errors:
file.cpp:12:1: error: ‘mutex’ in namespace ‘std’ does not name a type
file.cpp:13:1: error: ‘mutex’ in namespace ‘std’ does not name a type
file.cpp: In function ‘int main()’:
file.cpp:39:3: error: ‘thread’ is not a member of ‘std’
file.cpp:39:15: error: expected ‘;’ before ‘t’
Does anyone know whats going on?
Thanks!
Upvotes: 0
Views: 2830
Reputation: 17019
You can try the following:
#include <thread>
#include <iostream>
using std::cout;
using std::endl;
main() {
#ifndef(_GLIBCXX_HAS_GTHREADS)
cout << "GThreads are not supported..." << endl;
#endif
}
In fact, as of GCC 4.4, _GLIBCXX_HAS_GTHREADS
is undefined when libstdc++
is built because Cygwin implementation of pthread
lacks some functionality. The same was true for MinGW.
NOTE: GThreads, which is directly used by std::thread
, is a GCC wrapper around POSIX threads.
There are builds of MinGW-w64 based on GCC 4.7 and 4.8 targeting both 64-bit and 32-bit, which offer experimental support for std::thread
. Furthermore, yes, of course Cygwin and MinGW can co-exist as long as you switch between these 2 environments correctly, i.e. do not mix them in the PATH
environment variable.
Relevant links:
Upvotes: 1