1

I'm trying to run the following code, but eclipse is giving the errors "type thread cannot be resolved", "thread was not declared in this scope", "expected ; before t1".

enter image description here

#include <iostream>
#include "Tetris.h"
#include <Windows.h> //Sleep
#include <conio.h> //getch()
#include <thread>
#define SLEEP_TIME 1000
using namespace std;

void call_from_thread() {
    cout << "hello!" << endl;
}

int main(){
    /* some code... */ 
    thread t1(call_from_thread);

    /* some more code... */
    return 0;
}

So far i've tried the following:

enter image description here

enter image description here

enter image description here

enter image description here

I've also tried the -thread flag as I've seen someone suggesting in an answer here.

I've been looking on google and stackoverflow for hours without being able to solve the problem. "thread" still cannot be resolved and therefore I can't compile and generate a binary.

Any help would be very welcome thanks in advance

Mr. Phil
  • 1,099
  • 2
  • 14
  • 31
  • What version of GCC are you using? – ildjarn May 29 '14 at 03:47
  • Are you getting a compiler error or is it just Eclipse's code analyzer complaining? If it's the latter try adding `-D__GXX_EXPERIMENTAL_CXX0X__` to the last dialog. Also make sure the `__cplusplus` symbol is whatever the C++11 value is. If it's a compiler error, then did you make sure to download the version of MinGW that uses the Windows pthread implementation, and not native Windows threads? `std::thread` and friends don't work on the latter. – Praetorian May 29 '14 at 03:49
  • @ildjarn I don't know, where should I look for that information? thanks for answering – Mr. Phil May 29 '14 at 03:54
  • @FilipeGama : Run `gcc -v`. – ildjarn May 29 '14 at 03:55
  • @Praetorian I'm not sure whether it's a compiler error or not (http://i.imgur.com/D8UuqAb.png) all I know is that it won't generate a binary...-D__GXX_EXPERIMENTAL_CXX0X__ tried to add this, no success. I've downloaded MinGW some time ago, by the time I didn't really pay attention, how can I possibly know if this minGW uses windows pthread implementation or not? – Mr. Phil May 29 '14 at 04:03
  • @ildjarn I'm using windows – Mr. Phil May 29 '14 at 04:04
  • Download MinGW from [here](http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.0/threads-posix/seh/) (that's the 64-bit compiler, you should be able to find 32-bit version if that's what you need). Make sure Eclipse is able to find that gcc binary. Hopefully that'll fix your error. Oh, and the output from `gcc -v` should tell you what thread model your current version of MinGW was built with. – Praetorian May 29 '14 at 04:11
  • @FilipeGama : So? From your screenshots your toolchain in clearly still GCC... – ildjarn May 29 '14 at 04:24
  • (1) Juno is 2 years old. Please try it with the latest Eclipse, with Kepler. (2) Please make sure you [rebuild the index](http://stackoverflow.com/a/14135232/341970). (3) It's not clear to me whether the error comes from the static analyzer or from the compiler. I simply cannot decide based on the information you gave. – Ali May 29 '14 at 10:18
  • @ildjarn Gcc version 4.8.1 – Mr. Phil May 29 '14 at 15:18
  • @Ali I'm using juno because that was the version I was recommended...but I'll try that option if nothing else works. Please tell me which information you need and I'll gladly look for it since I really need this to get working – Mr. Phil May 29 '14 at 15:25

0 Answers0