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

19

我尝试使用std::this_thread::sleep_for()函数,但出现了错误:
error:'std::this_thread'未声明
包含了标志_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

8
你是否已经 #include <thread> - kennytm
3
请提供一个真实的测试用例,包括您编写的十行C++程序和构建命令。 - Lightness Races in Orbit
6
你是否使用-std=c++11标志进行编译构建? - Some programmer dude
3
MinGw不支持开箱即用的线程特性。 - Stephan Dollberg
@bamboon:那么,无法使用sleep_for()吗? - OlegG
显示剩余9条评论
1个回答

11

谢谢!编译器是MinGW,这就有所不同了。 - asgs
3
我完全不理解这个答案。提问者已经在使用MinGW了。首先,正是MinGW导致了这个问题。此外,那不是MinGW的链接。正确的链接应该是:https://sourceforge.net/projects/mingw/。 - Boann
1
mingw w64 显然有两种模式:https://dev59.com/_1oU5IYBdhLWcg3wi3SW - rogerdpack

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接