0

I originally asked a question regarding issues I am having getting the #include header file to function correctly. C++ multithreading errors. Specifically, I get the error that "'thread' was not declared in this scope". I am beginning to wonder if my original assumption that I was installing the mingw.thread.h header file incorrectly (located here: https://github.com/meganz/mingw-std-threads). This seemingly helps solve these issues for many people,

Can someone provide a description of how to install this file correctly?

These are the results when I run gcc -v on my terminal:

Using built-in specs.

COLLECT_GCC=c:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)

edit: To help, when I include the "mingw.thread.h" and compile, I get these errors:

error: #error To use the MinGW-std-threads library, you will need to define the macro _WIN32_WINNT to be 0x0501 (Windows XP) or higher.

#error To use the MinGW-std-threads library, you will need to define the macro _WIN32_WINNT to be 0x0501 (Windows XP) or higher.

T. Smith
  • 124
  • 8
  • have you changed your include to `#include "mingw.thread.h"`? – Alan Birtles Mar 15 '19 at 14:22
  • Yes. When I compile with the "mingw.thread.h", I get this output: error: #error To use the MinGW-std-threads library, you will need to define the macro _WIN32_WINNT to be 0x0501 (Windows XP) or higher. – T. Smith Mar 15 '19 at 14:51
  • have you tried defining the `_WIN32_WINNT` macro to `0x0501`? – Alan Birtles Mar 15 '19 at 14:54
  • Where would I do that? edit: I typed "#define _WIN32_WINNT 0x0501" onto the first empty line of my copy of mingw.thread.h and when compiled with "g++ Testing.cpp -std=c++11" it works! Thank you for your help! – T. Smith Mar 15 '19 at 15:10
  • Add `-D_WIN32_WINNT=0x0501` to your compiler command line – Alan Birtles Mar 15 '19 at 15:13
  • Given your newest comment, is there any issue with the thing I did? Im not fully aware of what "#define _WIN32_WINNT 0x0501" does – T. Smith Mar 15 '19 at 15:14
  • defining it in a file is not ideal as it really needs to have the same value everywhere, its much safer to define it on the compiler command line – Alan Birtles Mar 15 '19 at 15:33

1 Answers1

2

To use this header follow the instructions.

  1. Download the mingw.thread.h header and save it somewhere on your include path.
  2. Change #include <thread> to #include "mingw.thread.h" in your code
  3. If you aren't already you need to make sure that you define _WIN32_WINNT correctly. The easiest way to do this is via the gcc command line, e.g. add -D_WIN32_WINNT=0x0501.
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60