0

I wanted to create a program where I can call multiple threads. I started using #include <thread> but since it did not worked I followed the instructions from std::thread error (thread not member of std). Now my program looks like

#include <iostream>
#include "PATH/mingw.thread.h"



void task1(std::string msg)
{
    std::cout << "task1 says: " << msg;
}

int main() {
    std::thread t1(task1, "Hello from thread 1");
    std::thread t1(task1, "Hello from thread 2");

}

When I run this I get the following error in Visual Studio Code: fatal error C1189: #error: A C++11 compiler is required!

Also when I type g++ program.cpp -o programm, I get a long text of errors.

What can I do to fix this? Many thanks in advance

Phicalc
  • 75
  • 1
  • 6
  • ***#error: A C++11 compiler is required!*** Install the current version of MinGW using msys2. The VSCode documentation even tells you to do that on step 3 of this documentation: [https://code.visualstudio.com/docs/cpp/config-mingw](https://code.visualstudio.com/docs/cpp/config-mingw) The current MinGW has gcc-12.2 and it defaults to c++17 which won't have this issue. – drescherjm Jan 12 '23 at 18:57
  • 1
    yep, don't bodge threads into the ancient version of mingw you're using, upgrade to a modern version instead – Alan Birtles Jan 12 '23 at 18:57
  • 1
    Does this answer your question? [How can I install MinGW-w64 and MSYS2?](https://stackoverflow.com/questions/30069830/how-can-i-install-mingw-w64-and-msys2) – drescherjm Jan 12 '23 at 19:02
  • Note: If your mingw distribution isn't serving up at least GCC 9.3, and you're not being forced to use an antique compiler to support legacy systems, you're wasting your time. – user4581301 Jan 12 '23 at 19:02
  • On the long term you really should update to a modern compiler, on the short term explicitly specifying the standard to use might help: `-std=c++11` (or 14/17/20 – as long as supported). Older compilers might have slightly differing flags, too, like `-std=c++1a` (or 1b/1c) which had been used before the corresponding standard actually has been published. – Aconcagua Jan 12 '23 at 19:17
  • 2
    If you really want to continue using VSCode on Windows, I recommend installing MinGW-w64 via MSYS2 and the VSCode CMake Tools extension. But if you just want to try things out, the easiest way by far is to install [Visual Studio Community edition](https://visualstudio.microsoft.com/vs/), and create a "native console app" project. – rustyx Jan 12 '23 at 19:28
  • `#include "PATH/mingw.thread.h"` should be `#include ` once you get a modern version of MinGW and not such an old version. – drescherjm Jan 12 '23 at 20:02

0 Answers0