VScode 使用 #include<thread>的时候出现“thread is not a member of ‘std‘ “

发布于:2023-09-22 ⋅ 阅读:(157) ⋅ 点赞:(0)

VScode 使 #include的时候出现"thread is not a member of ‘std’ "

问题

环境

IDE: VSCode
编译器: MinGW

在这里插入图片描述
在这里插入图片描述

原因

这是因为MinGW没有thread类,对于跨平台的线程实现,GCC标准库似乎依赖于gthreads/pthreads库。如果这个库不可用,就像MinGW一样,std::thread、std::mutex、std::condition_variable类不会被定义。然而,各种可用的helper类仍然定义在系统头文件中。因此,这个实现没有重新定义它们,而是包含了这些头文件。

解决方案

https://github.com/meganz/mingw-std-threads

  1. 去github将项目克隆下来
  2. 将克隆下来的包中mingw.invoke.hmingw.mutex.hmingw.thread.h 三个文件 复制到 MinGW的存放目录下 “D:\MinGW\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++”
  3. 再将项目中的#include 改为 # include<mingw.thread.h> 重新编译即可

参考文章

C++解决“thread is not a member of ‘std‘ “


网站公告

今日签到

点亮在社区的每一天
去签到