【问题标题】:error: 'std::this_thread' has not been declared错误:“std::this_thread”尚未声明
【发布时间】:2012-11-24 08:52:14
【问题描述】:

我尝试使用 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

【问题讨论】:

  • 你有#include &lt;thread&gt;吗?
  • 请提供一个真实的测试用例,所以你的十行示例 C++ 程序和你的构建命令。
  • 您是否使用-std=c++11 标志构建?
  • MinGw 不支持开箱即用的线程功能。

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


【解决方案1】:

在 POSIX 线程中使用 MinGW,Luke。

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 2018-03-09
  • 1970-01-01
  • 1970-01-01
  • 2017-02-07
  • 2013-08-21
相关资源
最近更新 更多