Configuring C/C++ Development Environment in VS Code

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

  1. VS Code
  2. MinGW (GCC compiler for Windows)

Configuration Steps

  1. Install the C/C++ extension and Chinese language pack (optional) in VS Code
  2. Create a project folder (e.g., 'test') and open it in VS Code
  3. Add a new source file (main.c for C or main.cpp for C++)
  4. 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

Tags: VSCode c-programming cpp development-environment mingw

Posted on Sun, 12 Jul 2026 17:12:42 +0000 by golden_water