0

I am receiving the error "thread is not a member of std". I have tried every solution that I found online and none have worked so far. I have tried adding -pthread and --std=c++11 to the compiler and linker options and the compiler specs, as well as setting the language standard to ISO C++11. I am using Eclipse neon.3 with minGW 6.3.0-1, and I have updated all of my packages.

The code does run, but I would like to get rid of the error if possible. (EDIT: I was incorrect. When I choose to "Proceed with Launch" despite the error, it is running code that was compiled before I was using std::thread. The current code does not get run.)

Do I need a different version of mingw? Should I just switch to mingw-w64?

Here is my toolchain, for reference:

GCC Assembler

GCC Archiver

GCC C++ Compiler

GCC C Compiler

MinGW C Linker

MinGW C++ Linker

And the simple code that gives this error:

#include <thread>
#include <iostream>

void call_from_thread() {
    std::cout << "Hello!" << std::endl;
}

int main() {
    std::thread t1(call_from_thread);
    return 0;
}
  • 1
    What version of g++ and have you added `-std=c++11` to the compilation switches? – Richard Critten Jul 31 '17 at 16:33
  • What do you mean "the code does run"? Shouldn't it fail to compile if thread is not defined as a member of std? Is there any chance something is wrong with your header file? – patatahooligan Jul 31 '17 at 16:35
  • @RichardCritten gcc enabled c++14 by default since 6.1 – crackedmind Jul 31 '17 at 16:42
  • @patatahooligan When I run it, it notifies me that errors exist and I choose "proceed with launch" – Aidan Noel Jul 31 '17 at 16:45
  • @crackedmind was not assuming MinGW versioning and GCC version aligned – Richard Critten Jul 31 '17 at 16:50
  • @RichardCritten As noted in my post, it is version 6.3 and "I have tried adding -pthread and -std=c++11 to the compiler and linker options and the compiler specs" – Aidan Noel Jul 31 '17 at 16:50
  • 3
    Mingw32 does not support std::thread. See https://stackoverflow.com/questions/17242516/mingw-w64-threads-posix-vs-win32. You can switch to mingw64+winpthread (but TLS is utterly broken in that config) or use Boost.thread. – sbabbi Jul 31 '17 at 17:17

2 Answers2

0

The only way that I can reproduce that error w/ your example code is to not include the --std=c++11 switch. I notice in your text that you only put one dash before the switch, could that be your problem? Try two dashes.

I reproduced it here:

https://godbolt.org/g/GQFTc9

EDIT: BTW, in your comment you said:

When I run it, it notifies me that errors exist and I choose "proceed with launch"

This is running the result of a previous compilation, it is not just continuing and ignoring the error.

Rex Kerr
  • 91
  • 2
  • I'm aware it was running the result of a previous compilation, that's why my post says "...it is running code that was compiled before..." The missing hyphen was a typo, my bad. – Aidan Noel Aug 01 '17 at 05:27
0

With the advice of sbabbi, "Mingw32 does not support std::thread. ...You can switch to mingw64+winpthread (but TLS is utterly broken in that config) or use Boost.thread.", I decided to set up Boost and use that instead. I also switched to cygwin because it has the Boost libraries built in and I switched to Netbeans because installing Boost in eclipse was proving itself to be unnecessarily difficult.