thread is not a member of std 解决方案

本文探讨了不同版本的TDM-GCC中std::thread可用性的问题,具体来说,在TDM-GCC4.7.1中由于使用了Win32线程API导致std::thread被禁用,而在4.8.1及以后版本中因为采用了winpthreads线程库而使得std::thread可用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简单来说就算gcc4.7.1的API是 Win32 thread API.

转自stackoverflow


MinGW (which is included in TDM-GCC) comes with one of two APIs for threads: either winpthreads (based on the POSIX threads API, pthreads) or the Win32 thread API. If you have a version with the Win32 thread API, std::thread is disabled. TDM-GCC 4.7.1 uses the Win32 thread API, while TDM-GCC 4.8.1 and later come with winpthreads. That's why the compiler succeeded in one case but not the other.

This leads to 2 possible solutions for the 'thread' is not a member of 'std' problem:

  • Install a version of TDM-GCC that uses winpthreads (either standalone or with Code::Blocks). This means 4.8.1 or later.
  • Use the MinGW installer, which lets you choose which thread API to install. It also lets you choose what version of MinGW (which nowadays corresponds to the version of GCC included) to install, so you can even choose an older version such as 4.7.3, which is more stable than 4.8.1.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值