当前位置:首页 > IT技术 > 编程语言 > 正文

VS Code 配置C++开发环境
2022-01-01 23:10:16

参考 https://code.visualstudio.com/docs/cpp/config-mingw

1. 安装minGW,配置环境变量

2. 终端->配置默认生成任务,生成task.json 用于编译源文件

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "C:\MinGW\bin\g++.exe",//编译器路径
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}", //要编译的文件
                "-o",
                "${fileDirname}\${fileBasenameNoExtension}.exe"//生成的可执行程序
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "编译器: C:\MinGW\bin\g++.exe"
        }
    ]
}

 

3.运行->添加配置,配置launch.json文件
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\${fileBasenameNoExtension}.exe",//要调试的文件
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\MinGW\bin\gdb.exe",//调试器路径
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask":"C/C++: g++.exe 生成活动文件"//与task.json的label要一致
        }
    ]
}

 

 

本文摘自 :https://www.cnblogs.com/

开通会员,享受整站包年服务立即开通 >