c++ - MinGW 错误 : ‘thread’ is not a member of ‘std’

标签 c++ multithreading c++11 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 进行交叉编译,所以我被卡住了。

最佳答案

这个错误说明你使用的STL没有包含C++11的所有特性。

要在 Windows 中访问 C++11 线程,您需要使用 posix-threads 构建 Mingw。在这里您可以找到 Mingw-Builds v4.8.1:http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.1/64-bit/threads-posix/sjlj/

关于c++ - MinGW 错误 : ‘thread’ is not a member of ‘std’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21211980/

相关文章:

c++ - 从 Class<U> 调用 Class<T> 的私有(private)构造函数

javascript - 让网络 worker 更快、毫不拖延地开始

c++ - C/C++ 中的线程,任何标准?

multithreading - Play 2.0框架-主应用程序周期的持久线程?

c++ - 从字符串文字到 char * 的转换

c++ - 为什么包裹在函数中的 GAS 内联汇编为调用者生成与纯汇编函数不同的指令

c++ - 为什么不调用虚拟基础非默认构造函数,除非大多数派生基础显式调用它们?

c++ - 如何通过分隔符标记字符串?

c++ - 为什么我在编译 hello world c++ 文件时得到 "does not name a type"

C++1 1's "default”只能应用于特殊成员函数?