在VScode上配置C/C++环境

主要流程

  • 一、下载并安装VScode
  • 二、下载MinGw
    • 配置环境变量
    • 使用.c文件配置C
    • 运行程序
  • 参考链接


一、下载并安装VScode

VScode下载链接
安装下载步骤下载,然后按照傻瓜式安装就行
在VScode上配置C/C++环境_第1张图片
在VScode上配置C/C++环境_第2张图片
在VScode上配置C/C++环境_第3张图片

二、下载MinGw

MinGw下载链接
进去后往下翻找到 x86_64-posix-seh 点击下载
在VScode上配置C/C++环境_第4张图片
安装并解压该文件

记住你的解压路径,环境配置的时候需要用上

在VScode上配置C/C++环境_第5张图片

配置环境变量

此电脑单击右键属性

第五步新建,然后把解压好的MinGw路径放到如图所示
路径要到bin目录下才行,然后依次点击确定

在VScode上配置C/C++环境_第6张图片
验证一下是否成功
Win+r,输入cmd,再输入gcc -v

图为配置成功,否则环境变量配置失败

在VScode上配置C/C++环境_第7张图片

使用.c文件配置C

  1. 安装Chinese中文语言包

    打开vscode,安装中文插件,安装好了后重新启动软件

因为我已经安装了,所以是中文

在VScode上配置C/C++环境_第8张图片

  1. 安装C/C++

同理安装

在VScode上配置C/C++环境_第9张图片

  1. 新建一个文件夹,并在文件夹下新建一个文件:hello.c
#include 
int main()
{
     
    printf("hello world!\n");
    getchar();
    return 0;
}
  1. 按F5调试,默认配置
    在VScode上配置C/C++环境_第10张图片
    修改launch.json文件并保存
{
     
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
     
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "E:\\MinGW\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0 (1)\\mingw64\\bin",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\MinGW\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0 (1)\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
     
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe build active file"
        }
    ]
}
  1. 使用Shift+Ctrl+p,如图所示操作
    在VScode上配置C/C++环境_第11张图片
    在VScode上配置C/C++环境_第12张图片
    在VScode上配置C/C++环境_第13张图片
    修改tasks.json文件并保存
{
     
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
     
            "label": "C/C++: gcc.exe build active file",
            "type": "shell",
            "command": "E:\\MinGW\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0 (1)\\mingw64\\bin\\gcc.exe",
            "args": ["-g","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe"],"options": {
     "cwd": "E:\\MinGW\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0 (1)\\mingw64\\bin"},"problemMatcher": ["$gcc"]
        }
    ]
}

运行程序

按F5运行程序
在VScode上配置C/C++环境_第14张图片

参考链接

官方文档
参考详细配置

你可能感兴趣的:(C语言学习,c语言)