Vscode 配置 c++ 编译环境踩坑记录

task.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "task g++",
			"command": "C:\\Environment\\mingw64\\bin\\g++.exe",	//修改为自己路径
			"args": [
				"-g",	//g++ -g
				"${file}",	//g++ -g main.cpp
				"-o",	//g++ -g main.cpp -o
				"${fileDirname}\\${fileBasenameNoExtension}.exe"	//g++ -g main.cpp -o main.exe
			],
			"options": {
				"cwd": "${workspaceFolder}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"presentation": {
				"panel": "shared"
			}
			
	
		}
	]
}

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: 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": true,   //改为true
            "preLaunchTask": "task g++",    //新增项
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Environment\\mingw64\\bin\\gdb.exe", //MinGW位置
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

setting.json

{
    "tabnine.experimentalAutoImports": true,
    "editor.fontSize": 17,
    "editor.renderWhitespace": "all",
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    "terminal.integrated.profiles.windows": {
        "Git Bash": {
            "source": "Git Bash"
        },

        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "cmder":{ //使用 cmder 作终端
            "path": "C:\\KcSoftware\\cmder\\vendor\\git-for-windows\\bin\\bash.exe",
            "args":[]
        },
    },
    
}

F5 运行错误

> Executing task: C:\Environment\mingw64\bin\g++.exe -g d:\MyCodeSpace\VsCode\vscode-test\hello.cpp -o d:\MyCodeSpace\VsCode\vscode-test\hello.exe <

/usr/bin/bash: C:Environmentmingw64bing++.exe: command not found
终端进程“C:\Program Files\Git\bin\bash.exe '--login', '-c', 'C:\Environment\mingw64\bin\g++.exe -g d:\MyCodeSpace\VsCode\vscode-test\hello.cpp -o d:\MyCodeSpace\VsCode\vscode-test\hello.exe'”已终止,退出代码: 127。

在这里插入图片描述

原因

设置了默认 shell 为 git bash,注掉这一句调试正常,在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值