保姆级VS Code配置C语言环境

本文详细介绍了如何在Visual Studio Code(VSCode)中配置C语言的开发环境,包括下载和安装VSCode、安装C/C++插件、下载MinGW编译器并配置环境变量,以及测试和配置VSCode的相关设置。通过步骤演示,确保用户能够成功建立C语言的开发环境并进行编译运行。
摘要由CSDN通过智能技术生成

1.下载并安装VS Code

官网:Visual Studio Code - Code Editing. Redefined

2. 安装C/C++插件

27880d414a878501958ccaf8f8a3a1d3.jpeg

3. 下载编译器MinGW解压并配置环境变量

下载链接:MinGW-w64 - for 32 and 64 bit Windows - Browse Files at SourceForge.net

8f58d2f9b3d658fe2086f19c5676d478.jpeg

解压:

7872e43ccd0489bb176aad0073a9e340.jpeg

5.1 配置环境变量

复制bin文件夹所在路径

右键此电脑->属性->高级系统设置->环境变量->选择Path->编辑->新建->粘贴复制的bin路径,最后确定即可

f8260739c987e102d0449e8f761bc44b.jpeg

6cff1d8c058c0c8846579afd6409aab9.jpeg

c7ca4ffc141dc2bbf604881a95268c3b.jpeg

129b6fa008ae9304a4a46db73f7fce5c.jpeg

4. 测试编译器是否安装成功

win+r打开运行,输入cmd,输入gcc -v回车。如果出现下图证明成功

531d1d268e3d307ff1edf56ed951f2b7.jpeg

5.配置VS Code

1. 新建文件夹作为项目文件,在VSCode中打开文件夹,选择刚刚新建的文件夹,在导航栏中选择新建文件,文件名以.c结尾

37a26eeffddbc28c8b1db1ee38bf04b7.jpeg

2. 再新建一个.vscode文件夹,在里面创建:c_cpp_properties.json、launch.json、tasks.json

35e81b8f6e65b560041c489866a539a2.jpeg

c_cpp_properties.json的配置。注意:红框中的路径需要跟据自己编译器的位置进行更改

ac02e13b34f51bae57317ba3a1d8da5e.jpeg

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "F:/C/mingw64//include/**",
                "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++",
                "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32",
                "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward",
                "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
                "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed",
                "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "${workspaceRoot}",
                    "F:/C/mingw64//include/**",
                    "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++",
                    "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32",
                    "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward",
                    "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
                    "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed",
                    "F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include"
                ]
            }
        }
    ],
    "version": 4
}

launch.json的配置miDebuggerPath属性里的内容也要改

5fc9654be37c8c7b18eb3f477e420c8f.jpeg

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "cmd",
            "preLaunchTask": "echo",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "&",
                "echo.",
                "&",
                "pause"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole":true
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "F:\\C\\mingw64\\bin\\gdb.exe",// 自己电脑的gdb
            "preLaunchTask": "echo",//这里和task.json的label相对应
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
 
        }
    ]
}

tasks.json的配置

27e75b09cb0612198e72e95afa028243.jpeg

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g", 
                "${file}", 
                "-o", 
                "${fileBasenameNoExtension}.exe",
                "-fexec-charset=GBK"//解决中文乱码
            ]
        }
    ],
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared", 
        "showReuseMessage": true,
        "clear": false
    }
}

6. 运行

编写hello world

b0bf14a300b4513f3aa49398bc70c0b0.jpeg

关于VSCode中配置C语言的讲解到这里就结束了,如果有什么疑问的地方欢迎留在评论区,谢谢支持~
e65a4762b8e64e5e97934c982cb8af16.jpeg

 

 

 

  • 6
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EurekaO-O

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值