这个问题困扰了我很久,终于在官方文档上找到了答案,网上有很多版本,我都试过了,没有解决我的问题,可能是我自己没仔细看吧?废话不多说上图?
launch.json.文件
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
注意1:“miDebuggerPath”:这里的路径不要在 设置环境变量 哪里复制,应该在这里
鼠标右击gcc-
复制文件夹地址,用这个,路径"C:\msys64\mingw64\bin\gdb.exe"当然是你自己电脑的对应位置
tasks.json文件:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:/msys64/mingw64/bin/g++.exe",
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:/msys64/mingw64/bin/g++.exe"
}
],
"version": "2.0.0"
}
注意:2,该preLaunchTask设置用于指定启动前要执行的任务。确保它与tasks.json文件label设置一致。
注意:3,写文件明的时候不要用中文