0

I am using g++ --version "g++.exe (MinGW.org GCC-6.3.0-1) 6.3.0" While running this program getting 'thread' was not declared in this scope error even after included thread header file.

.\DemoThread.cpp:17:5: error: 'thread' was not declared in this scope thread testThread(funThread, 5); ^~~~~~ .\DemoThread.cpp:19:5: error: 'testThread' was not declared in this scope testThread.join();

Code :

#include<iostream>
#include<thread>

using namespace std;

void funThread(int num) {
   for(int i =0; i< num; i++) {
        cout<< "I am in thread" << endl; 
   }

}



int main() {

    thread testThread(funThread, 5);
    testThread.join();

    return 0;
}

Compiling using below command : g++ -Wall -g -std=c++11 .\DemoThread.cpp -o Demothread

R_K
  • 803
  • 1
  • 7
  • 18
  • Some MinGW distributions just don't support threading. You might have one of them. [Here's a link to installation instructions for a much more up-to-date compiler](https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2) that does (and has a package manager with an impressive ecosystem of support libraries and tools). – user4581301 Feb 01 '22 at 18:19
  • try add ```-lpthread``` or ```-pthread``` to compile options – Arseny Staroverov Feb 01 '22 at 19:30

0 Answers0