threads in code::blocks

Jul 16, 2015 at 1:42pm
so i'm trying to use a thread in my program and i'm using code::blocks and it doesn't work giving my the error: 'thread' was not declared in this scope.
now i change the settings of the compiler to support c++11,
and from my searches around the web the only solution i found was that i need
to change the MinGW, and since i'm a beginner i don't know what it means snd how to change it even though a lot of time searching the web.

what is the problem and how to solve it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  #include <iostream>
#include "rabbit.h"
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <conio.h>
#include <thread>
#include <chrono>

#define BOUT(expr) cout << expr ; fout<< expr
using namespace std;

char theK;
bool ok = true;

void kkk();

int main(){
cout<<"hello";
thread t1 (kkk);
t1.join;

return 0;
}

void kkk(){
    cin>>theK;
    while(theK== 'k'){
    ok=false;
    theK='l';
    }
    while(theK!='k'){
    cin>>theK;
    }
}




the error shows in the (thread t1 (kkk);) line.
the reason there so many includes is because i'm not showing all the program
and i need them later.
thank you
Jul 16, 2015 at 1:48pm
Take a look here:

http://www.mingw.org/

You probably need to download/install the latest version of the compiler suite.
Jul 16, 2015 at 2:17pm
Codeblocks default compiler doesn't support std::thread i think you need gcc 4.9 or higher.
Jul 16, 2015 at 3:29pm
I want to add that Code::Blocks doesn't install MingW to it's default location on Windows. It actually keeps a copy of it within it's own Program Folder so simply installing the latest MingW isn't enough to fix this. You will need to either copy over the existing installation (bad solution) or create another compiler profile on C::B pointing to the latest MingW and its tool chain (correct solution).
Jul 16, 2015 at 4:25pm
A MinGW build with standard library support for C++11 threads:
http://www.cplusplus.com/forum/beginner/169434/#msg847452
Jul 20, 2015 at 1:26pm
thank you it works now
Topic archived. No new replies allowed.