C is close to the machine and its toolchain is small. This guide covers compiling, running, debugging and building C in VS Code.
Install a compiler
- •Windows: install MSYS2 then
pacman -S mingw-w64-x86_64-gcc(gives gcc + gdb). - •macOS:
xcode-select --install(provides clang, which compiles C). - •Linux:
sudo apt install gcc gdb make.
Verify: gcc --version
VS Code
Install the C/C++ extension by Microsoft. It provides IntelliSense, code navigation and a debugger front-end for gdb/lldb.
Write, compile and run
Create main.c:
#include <stdio.h>
int main(void) {
int score = 21;
printf("Score: %d\n", score);
return 0;
}Compile with warnings on, then run:
gcc -Wall -g main.c -o main
./mainDebug it
The -g flag embeds debug info. Press F5, accept the generated gdb configuration, set breakpoints and step through — invaluable for tracking pointer and memory bugs.
Build with Make
A Makefile automates compilation for multi-file projects:
main: main.o util.o
gcc main.o util.o -o main
%.o: %.c
gcc -Wall -g -c $< -o $@Then just run make. It recompiles only the files that changed — the foundation of nearly every C build.