【发布时间】:2022-01-27 09:02:53
【问题描述】:
我希望在代码中出现编译错误时不启动调试器。这种情况发生在我构建成功,然后我做了一些无法编译的更改,当我启动调试器时,构建失败,但调试器仍然使用旧的可执行文件启动。
我知道Features -> Debug -> On task errors 选项,但它不会改变这种行为。
我在 Windows 上拥有最新版本的 VS Code、标准 C++ 扩展和 mingw。 这是我的标准配置:
.code-workspace
{
"folders": [
{
"path": ".."
}
],
"settings": {
"debug.onTaskErrors": "abort"
}
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - debug",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe debug build"
},
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe debug build",
"command": "D:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": ["-std=c++17","-Wall","-Wextra","-D","LOCAL","-g","${file}","-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: \"D:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe\""
},
]
}
我还需要做什么?
【问题讨论】:
-
构建失败时不要点击仍然运行按钮。
-
只运行你的编译任务,不要尝试同时运行调试器。
-
@sweenish,抱歉,我不明白你在说什么“仍然运行”按钮。我记得在 Visual Studio 中是这样的,但在 Visual Studio Code 中从未见过。我只想按
F5并构建和运行我的代码,我不想单独做。
标签: c++ visual-studio-code configuration vscode-settings