24


Greetings,

I've recently moved out of my unix shelter to test a supposedly cross-platform networking library only to discover that mingw doesn't like to be fed c++11 stuff.

I presume that I'm missing the required headers since Win7 doesn't come packed with c++11 support.

It compiles just fine with VS2012
but g++ refuses to.

error: 'thread' in namespace 'std' does not name a type
error: 'mutex' in namespace 'std' does not name a type

The question is:

How do I get a copy of c++11 headers/libs i.e. < thread > without using the ones provided by VS2012 installation.

P.S. #1 I tried mingw-get update but it still wont find < thread >
P.S. #2 I am also using -std=c++11


Sincerely,
Chris.

gifnoc-gkp
  • 1,506
  • 1
  • 8
  • 16
  • 1
    Try googling for something like "rubenvb mingw threads gcc" and download one of those distributions. And don't forget to thank rubenvb when you meet him – Andy Prowl Jul 09 '13 at 15:09
  • 1
    The [builds here](http://sourceforge.net/projects/mingwbuilds/?source=directory) also support threads. For rubenvb builds, use the `experimental-stdthread` ones. – Jesse Good Jul 09 '13 at 15:13
  • @Jesse Good Alright thanks! – gifnoc-gkp Jul 09 '13 at 15:16
  • 1
    You might also want to try VC++. It _is_ the standard compiler for Windows, and while it has its defaults, it works acceptably well, as long as you avoid its GUI. – James Kanze Jul 09 '13 at 15:20
  • 1
    @James Kanze It's too heavy, confusing and I'm used to writing makefiles and using gdb for debugging. Anyway, thanks for your tip :). – gifnoc-gkp Jul 09 '13 at 15:23
  • @TheOtherGuy The compiler (`cl`) is just a C++ compiler, like g++. You can (and I usually do) still use makefiles and all the rest. (GNU make is a lot more powerful the MSBuild, and XML is one of the few things whose syntax is as bad as that of make.) As for debugging: if your main platform is Linux, debug there, and only port debugged code to Windows. – James Kanze Jul 09 '13 at 15:27
  • @James Kanze So you're saying that I should try 'gnu make' provided by MSYS with vc++? I haven't thought of that. But I doubt vc++ takes the same arguements with g++. – gifnoc-gkp Jul 09 '13 at 15:31
  • 1
    @TheOtherGuy It certainly doesn't. But then, you already have to manage several sets of flags for different build types. This is easily handled by means of if's in the makefile, or include's with a path built up using `$(arch)` or `$(shell uname -s)` (if you've got CygWin installed and in your path). – James Kanze Jul 09 '13 at 16:40
  • @JamesKanze Alright, thanks for you time! Here's my vote :P – gifnoc-gkp Jul 09 '13 at 18:08
  • See also https://stackoverflow.com/questions/17242516/mingw-w64-threads-posix-vs-win32 – rogerdpack Oct 25 '18 at 04:40

2 Answers2

16

These MinGW-w64 builds support C++11 threads,atomic operations etc.

  1. MinGW-builds are now integrated into the MinGW-w64 project
  2. MinGW-builds (project is old and will not be updated, see point above)
  3. MinGW-w64 rubenvb 64-bit and 32-bit builds

Note that MinGW-w64 is not 64-bit only, but does support it, unlike the old MinGW(.org) which is missing quite a lot of the new Vista+ APIs, and of course 64-bit support.

rubenvb
  • 69,525
  • 30
  • 173
  • 306
gifnoc-gkp
  • 1,506
  • 1
  • 8
  • 16
  • rubenvb's build works for x86_64, but it fails to link 32 bit object files, as it lacks the 32bit libs sadly there is no i686 build. – Thomas Sep 11 '13 at 06:26
  • 1
    @Thomas There's a seperate section for i686 ... google `rubenvb i686`. – gifnoc-gkp Sep 13 '13 at 20:29
  • 2
    @Thomas 32 bit: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/ – gifnoc-gkp Sep 13 '13 at 20:29
6

Look also here: https://github.com/meganz/mingw-std-threads This is a lighter, native implementation of std::thread and others, without using the win32 port of pthreads.

Alexander Vassilev
  • 1,310
  • 13
  • 20