只需修改默认生成的tasks.json和launch.json中的两行配置即可。
1. tasks.json中的修改
将args中的 ${fileDirname}\\${fileBasenameNoExtension}.exe
修改为 :
${workspaceFolder}/build/${fileBasenameNoExtension}.exe
"args": [
"-g",
"${file}",
"-o",
// "${fileDirname}\\${fileBasenameNoExtension}.exe"
"${workspaceFolder}/build/${fileBasenameNoExtension}.exe"
],
2. launch.json中的修改
将configurations中的program的值 ${fileDirname}\\${fileBasenameNoExtension}.exe
, 修改为:
${workspaceFolder}/build/${fileBasenameNoExtension}.exe
"configurations": [
{
"name": "gcc.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
// "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"program": "${workspaceFolder}/build/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\IDE\\VScode\\mingw64\\bin\\gdb.exe", // 注意此处为本机的gdb.exe路径,需要自己配置
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]