错误:'std :: this_thread'尚未声明

时间:2012-12-06 10:32:37

标签: c++ c++11 gcc mingw glibc

我尝试使用std :: this_thread :: sleep_for()函数,但得到了错误
error: 'std::this_thread' has not been declared
标志_GLIBCXX_USE_NANOSLEEP包括。
还需要什么来强迫它发挥作用?
MinGW ==> gcc版本4.7.2(GCC)

SSCCE:

#include<thread>

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

命令行:

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

编译结果:

ssce.cpp: In function 'int main()':
ssce.cpp:4:8: error: 'std::this_thread' has not been declared

1 个答案:

答案 0 :(得分:7)

将MinGW与POSIX线程一起使用,Luke。

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