error: 'std::this_thread' has not been declared

29,945

Use MinGW with POSIX threads, Luke.

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

Share:
29,945

Related videos on Youtube

OlegG
Author by

OlegG

Updated on July 09, 2022

Comments

  • OlegG
    OlegG almost 2 years

    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
    
    • kennytm
      kennytm over 11 years
      Have you #include <thread>?
    • Lightness Races in Orbit
      Lightness Races in Orbit over 11 years
      Please present a real testcase, so your ten-line example C++ program and your build command.
    • Some programmer dude
      Some programmer dude over 11 years
      Do you build with the -std=c++11 flag?
    • Stephan Dollberg
      Stephan Dollberg over 11 years
      MinGw doesn't support threading features out of the box.