问题遇到的现象和发生背景
vscode 版本1.70.0 中,只有一个特定文件夹内的程序可以生成可执行文件进行调试,其他文件夹和子文件夹都不可以。可能是我的 launch.json 或者 task.json 文件有问题,但是我不太知道怎么修改。
用代码块功能插入代码,请勿粘贴截图
// launch.json
{
"version": "0.2.0",
"configurations": [
// {
// "name": "(gdb) Launch",
// "preLaunchTask": "g++.exe build active file",
// "type": "cppdbg",
// "request": "launch",
// "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
// "args": [],
// "stopAtEntry": false,
// "cwd": "${workspaceFolder}",
// "environment": [],
// "externalConsole": true,
// "MIMode": "gdb",
// "miDebuggerPath": "E:/MinGW/bin/gdb.exe",
// "setupCommands": [
// {
// "description": "Enable pretty-printing for gdb",
// "text": "-enable-pretty-printing",
// "ignoreFailures": true
// }
// ]
// },
{
"name": "C/C++: gcc.exe 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "E:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe 生成活动文件"
}
]
}
// task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "g++.exe build active file",
"command": "E:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "E:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
},
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "E:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
运行结果及报错内容
The preLaunchTask 'g++.exe build active file' terminated with exit code-1.
launch:program 'xxxxxx.exe' does not exist
我的解答思路和尝试过的方法
我尝试过修改 launch.json 中的 program 和 cwd 根据网上的一些相关回答,但是都没有效果。
我想要达到的结果
想了解在其他文件夹中编写的代码都可以正常生成执行文件并调试的方法