Nearby lessons
11 of 124C - Configure C in VS Code
Configure C in VS Code by creating the three .vscode files — tasks.json to build, launch.json to debug, and c_cpp_properties.json for IntelliSense — so you can compile with one keypress.
The Three Configuration Files
VS Code stores per-project settings in a hidden folder named .vscode. For C you need up to three files in it:
| File | Controls | Triggered by |
|---|---|---|
tasks.json | The compile command | Ctrl + Shift + B |
launch.json | Running under the debugger | F5 |
c_cpp_properties.json | IntelliSense header paths | Automatic |
In simple words: tasks.json builds it, launch.json debugs it, c_cpp_properties.json makes autocomplete accurate. You only strictly need the first one.
tasks.json — The Build Task
Create .vscode/tasks.json with the content below. It compiles whichever file is currently open and names the executable after it:
Example02
What Those Compiler Flags Mean
| Flag | Effect |
|---|---|
-g | Include debug symbols so breakpoints work |
-Wall | Turn on all common warnings — catches real bugs |
-o name | Name the output file instead of the default a.out |
-Wextra | Even more warnings (optional but recommended) |
-std=c17 | Compile against a specific C standard |
Trainer's Note: Always compile with
-Wall. Beginners often ignore warnings, but in C a warning like "control reaches end of non-void function" is usually a real bug that will bite you later.launch.json — Debugging with F5
Create .vscode/launch.json. Adjust miDebuggerPath to match your system — on Linux and macOS it is simply gdb or lldb:
Example04
c_cpp_properties.json — Accurate IntelliSense
This file tells the extension where the standard headers live, so #include <stdio.h> resolves and autocomplete is correct:
Example05
Paths for Each Operating System
| OS | compilerPath | miDebuggerPath | intelliSenseMode |
|---|---|---|---|
| Windows | C:/mingw64/bin/gcc.exe | C:/mingw64/bin/gdb.exe | windows-gcc-x64 |
| Linux | /usr/bin/gcc | /usr/bin/gdb | linux-gcc-x64 |
| macOS | /usr/bin/clang | /usr/bin/lldb | macos-clang-x64 |
Use forward slashes in JSON, even on Windows. A single backslash starts an escape sequence, so
"C:\mingw64" is invalid JSON. Write C:/mingw64/bin/gcc.exe or double every backslash.Let VS Code Generate Them For You
You do not have to type these by hand. With a .c file open:
- Press Ctrl + Shift + P.
- Run C/C++: Edit Configurations (UI) — generates
c_cpp_properties.json. - Run Tasks: Configure Default Build Task → pick your gcc entry — generates
tasks.json. - Press F5 and choose C++ (GDB/LLDB) — generates
launch.json.
📝 Key Takeaways
- tasks.json = how to build (Ctrl + Shift + B).
- launch.json = how to run and debug (F5).
- c_cpp_properties.json = where IntelliSense finds headers.
- All three live in a .vscode folder inside your project.
- Change compilerPath to match where you installed GCC.
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3