std::this_thread::sleep_for() and GCC

前端 未结 4 486
傲寒
傲寒 2020-12-02 22:21

When I try to compile this simple program:

#include

void f() {
  std::this_thread::sleep_for(std::chrono::seconds(3));
}

int main() {
  std::         


        
相关标签:
4条回答
  • 2020-12-02 23:05

    Seems to work without the define on ubuntu 13.04 using gcc version 4.7.3

    0 讨论(0)
  • 2020-12-02 23:11

    Need to define _GLIBCXX_USE_NANOSLEEP on top of the source code.

    #define _GLIBCXX_USE_NANOSLEEP  //add it top of c++ code
    

    OR, Compile with following commamd:

    g++ a.cpp -o a -std=c++0x -D_GLIBCXX_USE_NANOSLEEP    //compile c++ code
    ./a       // run c++ code
    
    0 讨论(0)
  • 2020-12-02 23:12

    Confirmed that it doesn't work here as well. (Recent GCC 4.6 snapshot).

    You could do the obvious and simply define it before you include any std:: headers. A bit dirty but will work until GCC fixes it (unless this is intended behavior). The #define shouldn't break anything anyways. Either in source or -D_GLIBCXX_USE_NANOSLEEP flag to GCC.

    You might want to try using -std=gnu++0x rather than -std=c++0x, since gnu++0x often pulls in stuff like this.

    0 讨论(0)
  • 2020-12-02 23:25

    Additional information, in case it helps someone:

    I do not need to define _GLIBCXX_USE_NANOSLEEP in Ubuntu 11.10, gcc 4.6.1, glibc 2.13.

    But I do need to compile with -D_GLIBCXX_USE_NANOSLEEP on Gentoo, gcc 4.6.1, glibc 2.12.2.

    I am not going to compile the Gentoo system for updating the glibc. At least not before the weekend ;)

    0 讨论(0)
提交回复
热议问题