How to Set Up C Programming in VS Code on Windows 11 and Linux (GCC & MinGW)
Henrik Lindqvist
Setting up Visual Studio Code for C programming often frustrates beginners with missing include paths, 'gcc' is not recognized errors, or terminal consoles that close before output can be read.
VS Code is a lightweight editor, not a full IDE. To compile and debug C code, you need:
A C compiler toolchain (GCC & GDB).
The Microsoft C/C++ Extension for IntelliSense.
Configured
.vscode/tasks.json(for building) and.vscode/launch.json(for debugging).
Here is the exact setup for Windows 11 and Linux.
1. Install the GCC Toolchain
On Windows 11:
Install MinGW-w64 using the modern w64devkit standalone distribution or MSYS2:
Download w64devkit from its official GitHub releases.
Extract the folder to
C:\w64devkit.Open Windows System Environment Variables $\rightarrow$ Path $\rightarrow$ Click New $\rightarrow$ Add
C:\w64devkit\bin.Open PowerShell and verify:
gcc --version
gdb --versionOn Ubuntu / Debian Linux:
Run:
sudo apt update
sudo apt install build-essential gdb -y
gcc --version2. Install VS Code Extensions
Open VS Code (Ctrl + Shift + X) and install:
C/C++ (by Microsoft) – Provides syntax highlighting, auto-complete, and debugging integration.
Code Runner (optional, for 1-click execution).
3. Create a Project & Sample C Program
Create a new directory and file main.c:
#include <stdio.h>
int main() {
char name[50];
printf("Enter your name: ");
if (fgets(name, sizeof(name), stdin) != NULL) {
printf("Hello, %s Welcome to C programming in VS Code!\n", name);
}
return 0;
}4. Configure Automated Build Task (.vscode/tasks.json)
Press Ctrl + Shift + P $\rightarrow$ select Tasks: Configure Default Build Task $\rightarrow$ select C/C++: gcc build active file.
Ensure your .vscode/tasks.json matches:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc build active file",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}Press Ctrl + Shift + B anytime to compile your code into an executable.
5. Configure GDB Debugging (.vscode/launch.json)
Press F5 or create .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: Debug with GDB",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file"
}
]
}Troubleshooting Common Gotchas
'gcc' is not recognized as an internal or external command: VS Code was open before adding GCC to your Windows PATH. Close and restart VS Code completely.Terminal doesn't accept input in Code Runner: Go to Settings (
Ctrl + ,) $\rightarrow$ SearchrunInTerminal$\rightarrow$ Check Code-runner: Run In Terminal.Squiggly red lines under
#include <stdio.h>: PressCtrl + Shift + P$\rightarrow$ C/C++: Edit Configurations (UI) $\rightarrow$ Set Compiler path toC:/w64devkit/bin/gcc.exe.
Connect with KoderSolution 🚀
Master modern software engineering, scalable architectures, and advanced backend systems.
Read more architectural deep-dives, systems tutorials, and engineering guides on kodersolution.com.
Subscribe to @kodersolution for concise, animated system design breakdowns and technical shorts.
Follow our official page for daily development tips, architecture discussions, and community updates.
Recommended Resources & Courses
Henrik Lindqvist
Runs small, hardened Docker containers and Alpine builds. Likes automated backups, Terraform scripts, and keeping server configs reproducible.