VS Code 配置C语言

1、安装 mingw64

链接:https://pan.baidu.com/s/1SkrQqLljk_VB-6MMx7rJNw 
提取码:c2et

解压后找到文件的地址:如 E:\XXXX\mingw64\bin,将该地址复制到系统环境变量PATH中。

打开CMD,输入 gcc --version,即安装成功

2、VS Code 安装扩展:C/C++,Code Runner

 

3、 新建一个文件夹,创建任意c文件。

如 hello.c

#include <stdio.h>

int main(){
    printf("hello world");
    return 0;
}

4、点击运行后,生成 .vscode 文件夹 (也可以手动创建),配置三个文件c_cpp_properties.jsonlaunch.jsontasks.json。只有c_cpp_properties.jsonlaunch.json需要修改,其他问价可以直接复制。

① c_cpp_properties.json文件,需要修改E:\XXXX\mingw64\bin为mingw64解压地址。

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                "E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                "E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                "E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                "E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
                "E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

②launch.json文件

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", //要运行的文件
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\XXXX\\mingw64\\bin\\gdb.exe", // E:\XXXX\mingw64\bin为mingw64解压地址
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "complie" // 调试会话开始前执行的任务,类似于Ant,这里为我们的编译任务
        }
    ]
}

③tasks.json文件

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "complie",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g",
                "${fileBasename}",
                "-o",
                "${fileBasenameNoExtension}.exe",
                "-lstdc++"
            ],
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

5、配置完毕,回到hello.c,右键,选择Run Code,即可运行C文件。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值