VS Code配置C语言环境教程

前期准备

  • 下载安装vscode
  • 下载mingw64,网址https://sourceforge.net/projects/mingw-w64/files/
    在这里插入图片描述
    将下载好的mingw64解压到指定的目录,这个是我的路径D:\mingw64 解压好之后,还需要配置环境变量 将目录D:\mingw64\bin追加到环境变量path里
    在命令行里输入gcc -v,输出以下版本信息则表示minGW配置OK
    在这里插入图片描述
  • 安装C/C++插件
  • 建立配置文件
    建立一个文件夹,命名为VS-Code-C
    目录下创建.vscode目录(注意有一个点)
    在.vscode目录下创建一下三个配置文件
c_cpp_properties.json

launch.json      
   
tasks.json

在这里插入图片描述
配置文件里面的内容分别对用如下:
c_cpp_properties.json

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

launch.json

{
    "version": "0.2.0",
    "configurations": [ 
        {
            "name": "(gdb)c_launch",
            "type": "cppdbg",
            "request": "launch",
            "targetArchitecture": "x64",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            //替换电脑中的路径
            "miDebuggerPath": "D:/mingw64/bin/gdb.exe",
            "MIMode": "gdb",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "internalConsoleOptions": "openOnFirstSessionStart",
            "externalConsole": true,
            "preLaunchTask": "gcc"
        }
    ]
  }  

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "command": "gcc",
    "args": ["-Wall", "-g", "${file}", "-o", "${fileBasenameNoExtension}.exe"],
    "echoCommand": true,
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceFolder}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
  }  

测试配置结果

#include<stdio.h>

int main(){
    printf("xxg123xsg\n");
    
    system("pause");
    return 0;
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值