Vscode 配置C++ Mingw调试、编译环境-无需修改系统PATH变量的VS Code配置方法

一般的教程都要求把mingw 加入Path, 而对于有多个环境的程序员而言,加入PATH要反复切换,麻烦,现在解决如下

1)安装Microsoft C/C++ 插件;C/C++ Runner

2)在程序路径下建立.vscode

c_cpp_properties.json

Lisp 复制代码
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "D:\\SDK\\mingw730_64\\bin\\g++.exe", /*自己电脑中mingw64\\bin\\g++.exe的路径,两个反斜杠\\*/
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "${default}"
        }
    ],
    "version": 4
}

lauch.json

Lisp 复制代码
{
    "configurations": [
        {
            "name": "C/C++: g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\build\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [
                {
                    "name": "PATH",
                    "value": "D:\\SDK\\mingw730_64\\bin;${env:PATH}"
                }
            ],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\SDK\\mingw730_64\\bin\\gdb.exe", /*自己电脑中mingw64\\bin\\gdb.exe的路径*/
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ],
    "version": "2.0.0"
}

tasks.json

Lisp 复制代码
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\\SDK\\mingw730_64\\bin\\g++.exe", /*自己电脑中mingw64\\bin\\g++.exe的路径*/
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\build\\${fileBasenameNoExtension}.exe",
                "-fexec-charset=UTF-8",
                "-std=c++17"
            ],
            "options": {
                "cwd": "D:\\SDK\\mingw730_64\\bin\\" /*自己电脑中mingw64\\bin的路径*/
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

其中路径 D:\\SDK\\mingw730_64\\bin\\ 用自己的Mingw路径。

相关推荐
恋爱绝缘体19 小时前
2020重学C++重构你的C++知识体系
java·开发语言·c++·算法·junit
Z1Jxxx10 小时前
加密算法加密算法
开发语言·c++·算法
乌萨奇也要立志学C++10 小时前
【洛谷】递归初阶 三道经典递归算法题(汉诺塔 / 占卜 DIY/FBI 树)详解
数据结构·c++·算法
️停云️11 小时前
【滑动窗口与双指针】不定长滑动窗口
c++·算法·leetcode·剪枝·哈希
charlie11451419111 小时前
嵌入式现代C++教程: 构造函数优化:初始化列表 vs 成员赋值
开发语言·c++·笔记·学习·嵌入式·现代c++
IT=>小脑虎11 小时前
C++零基础衔接进阶知识点【详解版】
开发语言·c++·学习
在路上看风景12 小时前
01. C++是如何工作的
开发语言·c++
码农小韩12 小时前
基于Linux的C++学习——指针
linux·开发语言·c++·学习·算法
小L~~~12 小时前
绿盟校招C++研发工程师一面复盘
c++·面试
微露清风12 小时前
系统性学习C++-第十九讲-unordered_map 和 unordered_set 的使用
开发语言·c++·学习