MinGW 错误:“线程”不是“标准”的成员

新手上路,请多包涵

我正在尝试为 Windows 交叉编译一个简单的应用程序:

 #include <thread>

void Func(){
  return;
}

int main(){
  std::thread thr1(Func);
  thr1.detach();
  return 0;
}

这就是我得到的:

 $ i686-w64-mingw32-g++ -static-libstdc++ -static-libgcc -pipe -g -std=c++0x ./threadstutor.cpp
./threadstutor.cpp: In function ‘int main()’:
./threadstutor.cpp:8:3: error: ‘thread’ is not a member of ‘std’
./threadstutor.cpp:8:15: error: expected ‘;’ before ‘thr1’
./threadstutor.cpp:9:3: error: ‘thr1’ was not declared in this scope

实际上,这段代码在 Ubuntu 下用 g++ 编译就没有这个问题;但我需要为 Windows 进行交叉编译,在这里我被卡住了。

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

阅读 1.3k
2 个回答

已经有更好的选择: https ://github.com/meganz/mingw-std-threads 这是MinGW最常用的线程和同步C++11类的轻量级win32本机实现。这些是在可以与系统库共存的仅头文件库中实现的。它也支持 Windows XP,它没有条件变量的直接模拟。

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

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