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

7
  • #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 The current MinGW has gcc-12.2 and it defaults to c++17 which won't have this issue. Commented Jan 12, 2023 at 18:57
  • 1
    yep, don't bodge threads into the ancient version of mingw you're using, upgrade to a modern version instead Commented Jan 12, 2023 at 18:57
  • 2
    Does this answer your question? How can I install MinGW-w64 and MSYS2? Commented Jan 12, 2023 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. Commented Jan 12, 2023 at 19:02
  • 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, and create a "native console app" project. Commented Jan 12, 2023 at 19:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.