Turning Learners Into Developers
Codekilla
CODEKILLA
VS Code 7 min

C & C++ Setup in VS Code (Step-by-Step with MinGW)

Configure VS Code for C/C++ development with MinGW compiler and debugging ready to go.

Rahul Chaudhary Tue Apr 21 2026
What is MinGW and Why Do You Need It?

MinGW (Minimalist GNU for Windows) is a collection of freely available and open-source Windows-specific tools, including compilers for C and C++. When you write code in C or C++, you're creating text files that humans can read—but your computer needs those files translated into machine code it can execute. That's where MinGW comes in. It provides the GCC compiler (GNU Compiler Collection) that turns your .c and .cpp files into executable programs on Windows. VS Code is a fantastic editor, but it's just that—an editor. It doesn't compile or run your code by itself. By pairing VS Code with MinGW, you get a lightweight, powerful development environment without needing a heavy IDE like Visual Studio.

Why It Matters
  • Cost: Both VS Code and MinGW are completely free, giving you professional-grade tools without licensing fees or bloated installations.
  • Cross-platform skills: Learning GCC through MinGW prepares you for Linux and macOS environments where GCC is the standard compiler.
  • Control: You understand exactly what happens when you compile—no magic buttons hiding the build process from you.
  • Performance: VS Code is fast and customizable, consuming far fewer resources than traditional IDEs while still offering IntelliSense, debugging, and extensions.
  • Industry relevance: Many embedded systems, game engines, and performance-critical applications are written in C/C++—this setup gets you started on that path.
Step 1: Install MinGW-w64

First, you need to get the compiler onto your system. Head to winlibs.com and download the latest UCRT runtime release (not MSVCRT). Look for the .zip file labeled with your architecture—most modern systems use Win64 (x86_64). Don't download the installer versions; the portable zip gives you more control.

Once downloaded, extract the entire folder to a simple path like C:\mingw64. Avoid spaces in the path—compilers hate them. Inside, you'll see folders like bin, include, and lib. The bin folder contains gcc.exe, g++.exe, and gdb.exe—your compiler and debugger.

Add MinGW to your PATH: Open Windows search, type "environment variables," and select "Edit the system environment variables." Click Environment Variables, find Path under System variables, click Edit, then New, and paste C:\mingw64\bin. Click OK on everything. Open a fresh Command Prompt and type:

bash
gcc --version

You should see version information. If you get an error, restart your computer—Windows sometimes caches PATH changes.

Step 2: Install VS Code and Essential Extensions

Download VS Code from code.visualstudio.com and install it. Launch VS Code, click the Extensions icon (four squares on the sidebar), and install:

  • C/C++ by Microsoft (ms-vscode.cpptools)
  • Code Runner by Jun Han (optional, but makes running single files trivial)

The C/C++ extension provides IntelliSense (autocomplete), error squiggles, and debugging support. Code Runner adds a convenient "Run Code" button in the top-right corner.

Step 3: Create Your First Project

Make a dedicated folder for your C/C++ projects—something like C:\code\cpp-projects. Inside, create a new folder called hello-world. Open VS Code, click File > Open Folder, and select hello-world.

Create a new file called main.cpp and add this code:

cpp
#include <iostream>
using namespace std;

int main() {
    cout << "Hello from C++!" << endl;
    return 0;
}

Save it. Now you need to tell VS Code how to build this file.

Step 4: Configure Build Tasks

Press Ctrl+Shift+P to open the Command Palette, type "Tasks: Configure Default Build Task," and select C/C++: g++.exe build active file. VS Code creates a .vscode folder with a tasks.json file. Here's what a properly configured version looks like:

json
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

The -g flag includes debugging symbols. The ${file} variable represents your active file, and -o specifies the output executable name. Press Ctrl+Shift+B to build. You should see a main.exe appear in your folder.

Step 5: Set Up Debugging

Debugging lets you pause execution, inspect variables, and step through code line by line. Press Ctrl+Shift+P, type "Debug: Add Configuration," and select C++ (GDB/LLDB). Choose g++.exe - Build and debug active file. VS Code creates a launch.json:

json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++: g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}

Set a breakpoint by clicking left of a line number (a red dot appears). Press F5 to start debugging. Execution pauses at your breakpoint, and you can hover over variables to see their values.

Step 6: Configure IntelliSense

IntelliSense makes coding faster by suggesting completions and catching errors before you compile. Press Ctrl+Shift+P, type "C/C++: Edit Configurations (UI)," and verify these settings:

  • Compiler path: C:\mingw64\bin\g++.exe
  • IntelliSense mode: windows-gcc-x64
  • C++ standard: c++17 or newer

VS Code creates a c_cpp_properties.json in .vscode:

json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "C:\\mingw64\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

Now IntelliSense knows where to find standard libraries and how to interpret your code.

Quick Cheat Sheet
NeedReach for
Compile a single C++ fileg++ filename.cpp -o output.exe
Compile with debugging symbolsg++ -g filename.cpp -o output.exe
Compile C (not C++)gcc filename.c -o output.exe
Enable all warningsg++ -Wall filename.cpp -o output.exe
Use C++20 featuresg++ -std=c++20 filename.cpp -o output.exe
Run the compiled program.\output.exe in terminal
Build in VS CodeCtrl+Shift+B
Start debugging in VS CodeF5
Common Mistakes
  • PATH not updated: You typed gcc --version and got "'gcc' is not recognized." You either didn't add MinGW to PATH, or you need to restart your terminal (or PC) for changes to take effect.

  • Wrong compiler path in tasks.json: If your MinGW is in D:\tools\mingw64 but tasks.json still says C:\mingw64\bin\g++.exe, builds will fail. Always match the actual installation path.

  • Mixing C and C++ compilers: You wrote a .cpp file but used gcc instead of g++. While gcc can sometimes compile C++, g++ automatically links the C++ standard library—use it for .cpp files.

  • Forgetting to save before building: VS Code won't auto-save unless you enable it. Press Ctrl+S before hitting Ctrl+Shift+B, or you'll compile the old version of your file.

  • Spaces in file paths: If your project folder is C:\My Code\hello, the compiler arguments might break. Use underscores or hyphens: C:\My_Code\hello.

  • Using the wrong terminal: If you have Git Bash or WSL installed, VS Code might open those by default. MinGW executables work best in Command Prompt or PowerShell. Change your default terminal in VS Code settings if needed.

💡 Think Like a Programmer: Your editor and your compiler are separate tools—VS Code makes the compiler easier to use, but understanding what g++ does under the hood gives you the power to compile anywhere, even on servers without a GUI.

// was this useful?
Did this article answer your question?
// VS Code · published by Codekilla
// related articles

Keep Reading