Nearby lessons

11 of 124

C - 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:

FileControlsTriggered by
tasks.jsonThe compile commandCtrl + Shift + B
launch.jsonRunning under the debuggerF5
c_cpp_properties.jsonIntelliSense header pathsAutomatic
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
CCode Cell
1{
2 "version": "2.0.0",
3 "tasks": [
4 {
5 "label": "build active C file",
6 "type": "shell",
7 "command": "gcc",
8 "args": [
9 "-g",
10 "-Wall",
11 "${file}",
12 "-o",
13 "${fileDirname}/${fileBasenameNoExtension}"
14 ],
15 "group": { "kind": "build", "isDefault": true },
16 "problemMatcher": ["$gcc"]
17 }
18 ]
19}
Output
> Executing task: gcc -g -Wall main.c -o main <
Build finished successfully.

What Those Compiler Flags Mean

FlagEffect
-gInclude debug symbols so breakpoints work
-WallTurn on all common warnings — catches real bugs
-o nameName the output file instead of the default a.out
-WextraEven more warnings (optional but recommended)
-std=c17Compile 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
CCode Cell
1{
2 "version": "0.2.0",
3 "configurations": [
4 {
5 "name": "Debug C file",
6 "type": "cppdbg",
7 "request": "launch",
8 "program": "${fileDirname}/${fileBasenameNoExtension}",
9 "args": [],
10 "stopAtEntry": false,
11 "cwd": "${fileDirname}",
12 "externalConsole": false,
13 "MIMode": "gdb",
14 "miDebuggerPath": "C:/mingw64/bin/gdb.exe",
15 "preLaunchTask": "build active C file"
16 }
17 ]
18}
Output
(F5 compiles, then pauses at your breakpoints)

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
CCode Cell
1{
2 "version": 4,
3 "configurations": [
4 {
5 "name": "Win32",
6 "includePath": ["${workspaceFolder}/**"],
7 "compilerPath": "C:/mingw64/bin/gcc.exe",
8 "cStandard": "c17",
9 "intelliSenseMode": "windows-gcc-x64"
10 }
11 ]
12}
Output
(green squiggles under #include disappear)

Paths for Each Operating System

OScompilerPathmiDebuggerPathintelliSenseMode
WindowsC:/mingw64/bin/gcc.exeC:/mingw64/bin/gdb.exewindows-gcc-x64
Linux/usr/bin/gcc/usr/bin/gdblinux-gcc-x64
macOS/usr/bin/clang/usr/bin/lldbmacos-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:

  1. Press Ctrl + Shift + P.
  2. Run C/C++: Edit Configurations (UI) — generates c_cpp_properties.json.
  3. Run Tasks: Configure Default Build Task → pick your gcc entry — generates tasks.json.
  4. 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 Questions
Progress: 0 / 3