配置C

下载MinGW编译器

官网页面:MinGW-w64

直接下载链接:下载链接

直接下载的事64位系统的版本,下载下来直接解压就行。

配置MinGW编译器环境

找到解压的bin目录,然后加入系统变量的Path中:

验证是否配置成功:

配置VS Code

安装扩展:

自定义配置文件:

目录如下,主要需要自定义tasks和launch:

launch.json:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file", // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg", // 配置类型,这里只能为cppdbg
            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)  
            "program": "${fileDirname}/exe/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径    
            "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
            "cwd": "${fileDirname}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录  
            "environment": [],
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台  
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Users\\21333\\Desktop\\mywork\\CWork\\mingw64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与自己电脑安装的MinGw的路径对应
            "preLaunchTask": "g++.exe build active file", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc  
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "g++.exe build active file",
            "type": "shell",
            "command": "C:\\Users\\21333\\Desktop\\mywork\\CWork\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\exe\\${fileBasenameNoExtension}.exe",
                "-fexec-charset=GBK"
            ],
            "group": "build",
            "options": {
                "cwd": "C:\\Users\\21333\\Desktop\\mywork\\CWork\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

里面最好是用绝对路径,省事。

配置C++

这里先暂搁一下,等过段时间要写C++了再补充吧

参考资料:

使用VScode编写C语言程序 环境安装配置 保姆级教程_vscode配置c语言环境-CSDN博客