我正在尝试为 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 线程构建 Mingw。在这里您可以找到 Mingw-Builds v4.8.1:http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.1/64-bit/threads-posix/sjlj/ http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.1/64-bit/threads-posix/sjlj/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)