std::thread 错误(线程不是 std 的成员)

新手上路,请多包涵

我使用 macports 编译并安装了 gcc4.4。

当我尝试使用 -> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp …进行编译时:

  #include <thread>
 ...
  std::thread t(handle);
  t.join();
 ....

编译器返回:

  cserver.cpp: In member function 'int CServer::run()':
 cserver.cpp:48: error: 'thread' is not a member of 'std'
 cserver.cpp:48: error: expected ';' before 't'
 cserver.cpp:49: error: 't' was not declared in this scope

但是 std::cout <<... 编译得很好..

谁能帮我?

原文由 luis 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
1 个回答

我在使用 MinGW 的 Windows 上遇到了同样的问题。我在 github mingw-std-threads 上找到了用于 in 的包装器类,包括 mingw.mutex.h、mingw.thread.h 文件到全局 MinGW 目录修复了这个问题。我所要做的就是包含头文件并且我的代码保持不变

#include "mingw.thread.h"

...
std::thread t(handle);
...

原文由 Vlad Bezden 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题