C++11 thread 在 Windows 系统中无法使用问题解决

最近在Windows10上使用C++11的 thread 时遇到了 " 未定义标识符"thread" " 的问题,但是我已经包含了 <thread> 头文件,这种问题在Linux上就没有出现。

我Windows10上的 C++ 编译器用的时 MinGW,这个问题是由于目前 MinGW 还没有支持标准的 C++11 的 thread 线程库,咱也不知道为什么 C++11 都出来十多年了怎么 MinGW 还没支持 thread 库,不过可以通过下载相关头文件的方法来使用线程库,下载地址:

GitHub - meganz/mingw-std-threads: Standard threads implementation currently still missing on MinGW GCC on Windowshttps://github.com/meganz/mingw-std-threads里面有这么一句话:

 下载之后是个免安装的文件夹,如下:

我们需要把上述红色框中的几个头文件放到自己装 MinGW 时的路径下,具体的是:

mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++

然后在实际使用时需要将相应的的头文件换成上述显示的头文件的名字,比如原来的 <thread> 要变为 "mingw.thread.h",然后我这就正常了,具体的使用方法是一样的。

参考:

C++11 thread类在windows上无法使用。std 没有成员 thread、thread not member of std_Cris6866的博客-CSDN博客_std没有成员threadhttps://blog.csdn.net/weixin_43913500/article/details/106038580

猜你喜欢

转载自blog.csdn.net/Flag_ing/article/details/126967720