使用VSCode运行C语言

使用VSCode运行C语言

    • VSCode安装
    • Mingw-w64 下载
    • 安装VSCode 插件
    • 配置运行文件

VSCode安装

下载地址:https://code.visualstudio.com/Download

Mingw-w64 下载

下载地址:https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/

下载并解压后配置PATH
使用VSCode运行C语言_第1张图片
使用VSCode运行C语言_第2张图片
使用VSCode运行C语言_第3张图片
使用VSCode运行C语言_第4张图片

安装VSCode 插件

使用VSCode运行C语言_第5张图片

配置运行文件

使用VSCode运行C语言_第6张图片
使用VSCode运行C语言_第7张图片
使用VSCode运行C语言_第8张图片
使用VSCode运行C语言_第9张图片
使用VSCode运行C语言_第10张图片
使用VSCode运行C语言_第11张图片

  1. 新建一个工程,然后建一个.c文件,随便写点代码,运行它,.vscode文件夹,文件夹下会生成launch.json文件,另外可以通过在该文件夹下新建 tasks.json。
  2. 配置 launch.json文件
{
     
    "configurations": [
        {
     
            "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg", // 配置类型,这里只能为cppdbg
            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)  
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径 
            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
            "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录 
            "environment": [],
            "externalConsole": false, // 如果为true,则为调试对象启动控制台。如果为false,它在Linux和Windows上会显示在集成控制台中
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\软件安装位置\\mingw64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
            "preLaunchTask": "gcc",
            "setupCommands": [
                {
     
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
  1. 配置 task.json文件
{
     
    "version": "2.0.0",
    "command": "gcc",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}.exe"
    ],// 编译命令参数
    "problemMatcher": {
     
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "${workspaceRoot}"
        ],
        "pattern": {
     
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    },
    "group": {
     
        "kind": "build",
        "isDefault": true
    }
}
  1. 配置 c_cpp_properties.json 文件
{
     
    "configurations": [{
     
        "name": "MinGW64",
        "includePath": [
            "${workspaceFolder}/**",
            "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",
            "_UNICODE"
        ],
        "compilerPath": "D:\\软件安装位置\\mingw64\\bin\\gcc.exe",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "gcc-x64"
    }],
    "version": 4
}
  1. 运行
#include 
#include 

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

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