Compiling a C++ source file in Visual Studio Code with MinGW

I followed this instruction and configured C/C++ extension as follows:

    "configurations": [
            "name": "Win32",
            "includePath": [
            "defines": [
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "D:\\dev\\tools\\x86_64-12.2.0-release-win32-seh-rt_v10-rev0\\mingw64\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
    "version": 4

then I created and successfully compiled helloworld.cpp:

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    for (const string& word : msg)
        cout << word << " ";
    cout << endl;

I also was able to run the program I compiled by pressing triangle button at top-right corner, and IntelliSense also worked:

tasks.json was created automatically:

    "tasks": [
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\\dev\\tools\\x86_64-12.2.0-release-win32-seh-rt_v10-rev0\\mingw64\\bin\\g++.exe",
            "args": [
            "options": {
                "cwd": "D:\\dev\\tools\\x86_64-12.2.0-release-win32-seh-rt_v10-rev0\\mingw64\\bin"
            "problemMatcher": [
            "group": {
                "kind": "build",
                "isDefault": true
            "detail": "Task generated by Debugger."
    "version": "2.0.0"

My project tree looked like this at this point:

Then I set a breakpoint and it was triggered successfully when I started debug session:

Alternatively we use commands:

My plugin version:

6 Responses to Compiling a C++ source file in Visual Studio Code with MinGW

  1. dmitriano says:

    Using GCC with MinGW:

    Debug C++ in Visual Studio Code:
    Windows debugging with GDB (“miDebuggerPath”: “c:\\mingw\\bin\\gdb.exe”)

    Get started with CMake Tools on Linux:

    Visual Studio Code CMake Tools ignores custom kits?

  2. dmitriano says:

    How to configure VS Code’s CMake Tools Extension for GCC and MSYS Makefiles on Windows?

  3. dmitriano says:
    If you build the above code snippet with gcc you get the errors you mention. If you use g++ it build ok, this makes sense since g++ will make sure all the proper stuff it put together when build C++.

  4. dmitriano says:

    set PATH=C:\WINDOWS\system32;C:\WINDOWS
    set PATH=%PATH%;”D:\dev\tools\mingw64\bin”
    and then run VS Code, but the kits still not found.

Leave a Reply

Your email address will not be published. Required fields are marked *