3

I try to crosscompile some c++11 source with mingw on linux for windows. The code uses std::thread.

When i compile i always get some errors:

$ ../mingw/cross/bin/i686-w64-mingw32-g++  -std=c++11 -I include/ test.cpp -lstdthread -otest
In file included from test.cpp:4:0:
...
error: 'thread' in namespace 'std' does not name a type
...

I it possible to enable c++11 threads in mingw? The code compiles without any problems with the local g++.

Thank you,

regars Kevin

-edit-

I just downloaded the mingw somewhere in the internet, because i tried to get an as new as possible version:

../mingw/cross/bin/i686-w64-mingw32-g++  -v
Using built-in specs.
COLLECT_GCC=../mingw/cross/bin/i686-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/home/bmeier/source/mingw/cross/bin/../libexec/gcc/i686-w64-mingw32/4.8.1/lto-wrapper
Target: i686-w64-mingw32
Configured with: /home/drangon/work/mingw-w64-dgn_32/source/gcc-4.8.1/configure --target=i686-w64-mingw32 --disable-nls --disable-multilib --with-gmp=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-mpfr=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-mpc=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-isl=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-cloog=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --enable-languages=c,c++,objc,obj-c++ --disable-libstdcxx-pch --prefix=/home/drangon/work/mingw-w64-dgn_32/cross --with-sysroot=/home/drangon/work/mingw-w64-dgn_32/cross
Thread model: win32
gcc version 4.8.1 (GCC)

regards Kevin

Kevin Meier
  • 2,339
  • 3
  • 25
  • 52
  • Does gcc support c++11 threads on mingw? – Duck Jul 13 '13 at 00:35
  • Which exact version of MinGW GCC are you using? What is the output of `../mingw/cross/bin/i686-w64-mingw32-g++ -v`? And cross-compiling on a Linux system is usually easier (so perhaps install a Linux on your machine) – Basile Starynkevitch Jul 13 '13 at 05:53
  • I just wrote the version output in the start post. I always use linux to cross compile:-) Also now. I use xubuntu. Thank you for the help – Kevin Meier Jul 13 '13 at 10:15
  • possible duplicate of [std::thread is not a member of namespace std using Eclipse Kepler MinGW](http://stackoverflow.com/questions/18913542/stdthread-is-not-a-member-of-namespace-std-using-eclipse-kepler-mingw) Not exact, but it has the same answer. – rubenvb Sep 23 '13 at 13:52

3 Answers3

2

There is already a native implementation of std::thread and sync primitives, that works with any C++11 version of MinGW: https://github.com/meganz/mingw-std-threads

Alexander Vassilev
  • 1,399
  • 13
  • 23
1

Basically MinGW does not support threads on windows see the following link: http://www.cplusplus.com/forum/windows/82461/

Specifically _GLIBCXX_HAS_GTHREADS is not defined and the class thread in the header thread requires it. (It is built on gthreads).

You should try and use boost::thread for a win/linux compatible thread class

odedsh
  • 2,594
  • 17
  • 17
-1

Most probably you might have forgot to include thread header #include <thread>

twid
  • 6,368
  • 4
  • 32
  • 50