首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2013-01-02 
C++11 error: ‘sleep_for’ is not a member of ‘std::this_thread’背景:为了学习c11的多线程和lamda表达式

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 Wakely(a 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'

热点排行