C++11 error: ‘sleep_for’ is not a member of ‘std::this_thread’

背景:为了学习c++11的多线程和lamda表达式的特性,升级了gcc(从4.4.6到4.7.1),写完thread程序编译时却发现还是遇到了一些问题。

原因:GCC没有定义这个宏:_GLIBCXX_USE_NANOSLEEP

解决办法:编译时加上选项:-D_GLIBCXX_USE_NANOSLEEP

或者:修改gcc的c++config.h文件去定义这个宏
再或者:重新安装gcc且使用选项:--enable-libstdcxx-time

详情
(1)std::this_thread::sleep_for() and GCC
(2)来自Jonathan Wakelya maintainer of the GNU C++ Standard Library (libstdc++)的回答:
      What is _GLIBCXX_USE_NANOSLEEP all about?   

see also:C++11 'yield' is not a member of 'std::this_thread'

你可能感兴趣的:(C++11 error: ‘sleep_for’ is not a member of ‘std::this_thread’)