Enable C++ Development in VS Code on Windows (MinGW-w64 + GCC + GDB)
Step-by-step guide to configure C++ compiling and debugging in Visual Studio Code on Windows using MinGW-w64.
Prerequisites
- Windows 10/11 system
- Visual Studio Code
- MinGW-w64 (GCC + GDB), via MSYS2 or standalone
Step 1: Install the C/C++ extension
- Open VS Code.
- Press
Ctrl+Shift+Xto open Extensions. - Search for C/C++ by Microsoft.
- Click Install.
- Restart VS Code.
Step 2: Install MinGW-w64 (compiler + debugger)
Option A (recommended): Install via MSYS2
- Download MSYS2 from msys2.org.
- Open MSYS2 terminal and update packages:
pacman -Syu
- Install GCC and GDB:
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb
- Add
C:\msys64\mingw64\binto your system PATH.
Option B: Standalone MinGW-w64
- Download from mingw-w64.org.
- Install, then add the
binfolder to PATH.
Step 3: Verify installation
Open PowerShell or Command Prompt:
g++ --version
gdb --version
You should see GCC/GDB version info.
Step 4: Create a test project
- Create a folder:
mkdir C:\cpp-hello
cd C:\cpp-hello
- Open in VS Code:
code .
- Create
main.cpp:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, C++ from Windows with MinGW!" << endl;
return 0;
}
Step 5: Configure build tasks (tasks.json)
Create .vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C++: Build with g++",
"command": "g++",
"args": [
"-std=c++17",
"-g",
"main.cpp",
"-o",
"build\\main.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
Step 6: Configure debugging (launch.json)
Create .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++: Debug build/main.exe (GDB)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\main.exe",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "C++: Build with g++",
"stopAtEntry": false,
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe"
}
]
}
Step 7: Configure IntelliSense (c_cpp_properties.json)
Create .vscode/c_cpp_properties.json:
{
"version": 4,
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/msys64/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
]
}
Step 8: Build and run
- Build: Press
Ctrl+Shift+B. → Output:build\main.exe - Run:
.\build\main.exe
Output:
Hello, C++ from Windows with MinGW!
- Debug:
- Go to Run and Debug (
Ctrl+Shift+D) - Select C++: Debug build/main.exe (GDB)
- Start debugging, set breakpoints, step through code
Step 9: Common issues
g++not found: Ensure MinGW-w64binfolder is in PATH.- Debugger errors: Confirm
miDebuggerPathpoints togdb.exe. - IntelliSense mismatch: Update
compilerPath. - Spaces in PATH: Wrap paths in quotes inside tasks.
Quick reference
- Build:
Ctrl+Shift+B - Debug:
Ctrl+Shift+D→ Start - Compiler: MinGW-w64
g++ - Debugger:
gdb