VScode与mingw64配置C++环境,preLaunchTask"g++"已终止,退出代码为1解决办法2020
直接上两个文件最后的代码
如果结构差不多,是同一版本的mingw64,可以粘贴我的代码,注意一定要把"miDebuggerPath":项改为你自己mingw64的地址,注意地址的最后一项是gdb.exe
tasks.json
tasks.json中要注意
“command”: 项改为"g++",
“args”:项要修改
后面的
“group”:
“presentation”:
“problemMatcher”
保持不变
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "task g++",
"type": "shell",
//command
"command": "g++",
//args
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "silent"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
lachun.json
lachun.json中要注意
“program”:项的修改
“miDebuggerPath”:项修改为mingw64的地址,注意地址的最后一项是gdb.exe
{
// 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
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",//注意这个位置要修改才能生成正确的程序
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
// "miDebuggerPath": "/path/to/gdb",
//miDebuggerPath
"miDebuggerPath": "D:\\Program Files (x86)\\mingw64\\bin\\gdb.exe",//注意这个位置采用'\\'
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "task g++" //修改此项
}
]
}
以及:有的文章说要新建一个build文件夹,实测现在已经不需要了,只不过会把 .exe文件扔在根目录下罢了
参考:https://blog.csdn.net/qq_40969864/article/details/103158635