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.
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.
- 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.
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:
bashgcc --version
You should see version information. If you get an error, restart your computer—Windows sometimes caches PATH changes.
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.
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.
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.
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.
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++17or 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.
| Need | Reach for |
|---|---|
| Compile a single C++ file | g++ filename.cpp -o output.exe |
| Compile with debugging symbols | g++ -g filename.cpp -o output.exe |
| Compile C (not C++) | gcc filename.c -o output.exe |
| Enable all warnings | g++ -Wall filename.cpp -o output.exe |
| Use C++20 features | g++ -std=c++20 filename.cpp -o output.exe |
| Run the compiled program | .\output.exe in terminal |
| Build in VS Code | Ctrl+Shift+B |
| Start debugging in VS Code | F5 |
-
PATH not updated: You typed
gcc --versionand 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\mingw64buttasks.jsonstill saysC:\mingw64\bin\g++.exe, builds will fail. Always match the actual installation path. -
Mixing C and C++ compilers: You wrote a
.cppfile but usedgccinstead ofg++. Whilegcccan sometimes compile C++,g++automatically links the C++ standard library—use it for.cppfiles. -
Forgetting to save before building: VS Code won't auto-save unless you enable it. Press
Ctrl+Sbefore hittingCtrl+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.
Keep Reading
VS Code Shortcut Keys (Complete List)
Read on to explore vs code shortcut keys (complete list) — a beginner-friendly walkthrough by Codekilla.
Master CSS Emmet Shortcuts in VS Code
Read on to explore master css emmet shortcuts in vs code — a beginner-friendly walkthrough by Codekilla.
VS Code Emmet Shortcuts for HTML With Examples
Read on to explore vs code emmet shortcuts for html with examples — a beginner-friendly walkthrough by Codekilla.
