VS Code functions as a text editer but can be transformed into a full-fledged C/C++ development environment by installing necessary extensions and configuring compiler paths. This setup enables code editing, compilation, and debugging similar to IDEs like Code::Blocks.
Required Software
- VS Code
- MinGW (GCC compiler for Windows)
Configuration Steps
- Install the C/C++ extension and Chinese language pack (optional) in VS Code
- Create a project folder (e.g., 'test') and open it in VS Code
- Add a new source file (main.c for C or main.cpp for C++)
- Write test code and run using the debug button (creates tasks.json)
Configuration Files
tasks.json (Compiler Settings)
{
"tasks": [
{
"type": "cppbuild",
"label": "Build with GCC",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"*.c",
"-o",
"${workspaceFolder}\\output.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
launch.json (Debugger Settings)
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug with GDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\output.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Key Points
- tasks.json defines compiler settings (GCC path, source files, output executable)
- launch.json configures debugger settings (GDB path, executable name)
- For C++ projects, replace gcc.exe with g++.exe in tasks.json