19

I try to use std::this_thread::sleep_for() function but got the error
error: 'std::this_thread' has not been declared.
The flag _GLIBCXX_USE_NANOSLEEP included.
What else is needed to force it to work?
MinGW ==> gcc version 4.7.2 (GCC)

SSCCE:

#include<thread>

int main() {
  std::this_thread::sleep_for(std::chrono::seconds(3));
}

command line:

g++ -D_GLIBCXX_USE_NANOSLEEP -std=gnu++0x ssce.cpp -o ssce.exe

result of compilation:

ssce.cpp: In function 'int main()':
ssce.cpp:4:8: error: 'std::this_thread' has not been declared
legends2k
  • 31,634
  • 25
  • 118
  • 222
OlegG
  • 975
  • 3
  • 10
  • 30

1 Answers1

11

Use MinGW with POSIX threads, Luke.

http://sourceforge.net/projects/mingwbuilds/

ttldtor
  • 170
  • 4
  • 7
  • thank you! The compiler being MinGW made the difference. – asgs Nov 07 '15 at 18:49
  • 3
    I don't understand this answer at all. The asker is *already* using MinGW. It's MinGW that is causing this problem in the first place. Also, that is not the link to MinGW. It should be: https://sourceforge.net/projects/mingw/. – Boann Feb 26 '18 at 22:00
  • 1
    mingw w64 apparently has two modes: https://stackoverflow.com/questions/37358856/does-mingw-w64-support-stdthread-out-of-the-box-when-using-the-win32-threading – rogerdpack Feb 06 '19 at 05:37