c语言环境配置

1、下载x86_64-15.1.0-release-posix-seh-ucrt-rt_v12-rev0
下载地址为:
https://github.com/niXman/mingw-builds-binaries/releases#release-15.1.0-rt_v12-rev0

image

 

2、配置bin目录到环境变量PATH.
3、验证环境是否搭建成功
gcc --version

image

 4、vscode打开一个文件夹创建tasks.json,用于自动编译运行,utf-8编码。launch.json用于debug调试。

image

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "编译C程序",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g",
                "-finput-charset=UTF-8",
                "-fexec-charset=GBK",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "group": {
                "kind": "build"
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared",
                "clear": false,
                "showReuseMessage": false
            },
            "problemMatcher": "$gcc"
        },
        {
            "label": "编译并运行",
            "dependsOn": "编译C程序",
            "type": "shell",
            "command": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "options": {
                "cwd": "${fileDirname}"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            }
        }
    ]
}

launch.json

{
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "console": "integratedTerminal",
            "preLaunchTask": "编译C程序"
        }
    ],
    "version": "2.0.0"
}

test.c

#include <stdio.h>

int main(void) {
    // 单片机基础输出测试
    unsigned char a = 0x0F; 
    
    // %02X 会输出 "0F",而 %2X 可能会输出 " F" (带空格)
    printf("哈哈哈哈");
    
    return 0;
} 


按键ctrl+shift+b  回车运行  

image

 

5、如果不想快捷键运行的话,使用命令编译代码,命令运行
编译:gcc -g -finput-charset=UTF-8 -fexec-charset=GBK test.c -o test.exe
运行:.\test.exe

image

 


  



posted @ 2026-07-10 14:43  _Lawrence  阅读(2)  评论(0)    收藏  举报