MinGW错误:'thread'不是'std'的成员

Hi-*_*gel 13 c++ multithreading mingw c++11

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

#include <thread>

void Func(){
  return;
}

int main(){
  std::thread thr1(Func);
  thr1.detach();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

这就是我得到的:

$ 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
Run Code Online (Sandbox Code Playgroud)

实际上,如果使用g ++为Ubuntu编译,这段代码没有这样的问题; 但是我需要为Windows进行交叉编译,而在这里我被卡住了.

Ale*_*lev 16

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


Ser*_* K. 13

此错误意味着您使用的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/

  • 无法安装。它显示“无法下载repository.txt [0]” (3认同)