gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:39:30 30 4
gpt4 key购买 nike

我正在尝试为 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com