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

Ole*_*egG 11 c++ gcc mingw glibc c++11

我尝试使用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));
}
Run Code Online (Sandbox Code Playgroud)

命令行:

g++ -D_GLIBCXX_USE_NANOSLEEP -std=gnu++0x ssce.cpp -o ssce.exe
Run Code Online (Sandbox Code Playgroud)

编译结果:

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

小智 9

使用MinGW和POSIX线程,Luke.

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

  • 我根本不明白这个答案。提问者*已经*使用MinGW。首先是 MinGW 导致了这个问题。此外,这不是指向 MinGW 的链接。它应该是:https://sourceforge.net/projects/mingw/。 (2认同)