我正在尝试为 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 许可协议
此错误表示您使用的 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/