6

I have downloaded MinGW from the official website and installed it on my Windows 8.1 machine.

Running g++ --version gives me g++.exe (GCC) 4.8.1.

I am trying to compile the existing codebase in MinGW compiler but it is failing with the following error:

error: 'mutex' in namespace 'std' does not
name a type
     private: std::mutex m_Mutex;
              ^
error: 'condition_variable' in namespace 's

and many more errors related to locking and threading.!

I was able to compile the same codebase in Cygwin-64 without any issues. I need to build and compile successfully in MinGW in order to create some .dll files which would be compatible on MSVS.!

I have already referred the following links , but i couldn't get through the solution.

Getting std::thread/mutex to work under Win7 with mingw and g++ 4.7.2
MinGW 4.8.1 C++11 thread support

Your help would be greatly appreciated. Thanks.

Community
  • 1
  • 1
Shivaraj Bhat
  • 775
  • 1
  • 8
  • 18
  • 1
    Did you enable `-std=c++11`? – πάντα ῥεῖ Jan 14 '15 at 09:21
  • Are you using `-std=c++11` to ask for the C++11 language version? All these fancy threading classes are new to that version. – rodrigo Jan 14 '15 at 09:21
  • 1
    I m using -std=c++11 during compiling.! – Shivaraj Bhat Jan 14 '15 at 09:24
  • 2
    libstdc++ doesn't support most of the threads library if your compiler was configured with the win32 threading model, you need a version of gcc with posix threads. [This](http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.8.4/threads-posix/seh/) should be what you need. – user657267 Jan 14 '15 at 09:50
  • possible duplicate of [C++ mutex in namespace std does not name a type](http://stackoverflow.com/questions/14191566/c-mutex-in-namespace-std-does-not-name-a-type) – Rick Smith May 29 '15 at 19:30
  • Possible duplicate of [mingw-w64 threads: posix vs win32](https://stackoverflow.com/questions/17242516/mingw-w64-threads-posix-vs-win32) – rogerdpack Oct 25 '18 at 04:41

1 Answers1

7

The old MinGW from mingw.org does not support C++11 threading facilities.

A direct alternative would be to use MSYS2 and install MinGW-w64 compilers from there, which do support the required functionality. Follow the steps in that document, and do a:

pacman -Sy mingw-w64-i686-gcc

Which will get you a 32-bit MinGW-w64 GCC. You can call it from the "MinGW-w64 32-bit Shell", or by adding <MSYS2>\mingw32\bin to PATH.

rubenvb
  • 69,525
  • 30
  • 173
  • 306
  • I m compiling the codebase in Msys prompt. Since the codebase is having openSSL libraries and also netinet/in.h similar files, I m adding those paths while compiling as well. – Shivaraj Bhat Jan 14 '15 at 09:28
  • Here is command format that i m using for compiling the existing code..: g++ -std=c++11 -I /c/openssl-1.0.1i/openssl-1.0.1i/include/ -Iinclude -I /c/cygwin64/usr/i686-pc-cygwin/sys-root/usr/include -I /c/MinGW/mingw32/lib/gcc/min gw32/4.8.1/include -pthread source/main.cpp source/*/*cpp -lpthread -lssl -lcrypto – Shivaraj Bhat Jan 14 '15 at 09:28
  • 1
    You can also install openssl from MSYS2: `pacman -Sy mingw-w64-i686-opensll` and you won't have to add any additional paths when compiling using its compiler. Also: the Cygwin directory has no place there, ever. – rubenvb Jan 14 '15 at 09:32
  • Are you calling the new compiler from the MSYS2 shell? It won't magically replace your old MinGW install. – rubenvb Jan 14 '15 at 10:55