使用c++17进行VsCode调试失败



我遇到了一个问题,我可以在启用c++17标志的情况下构建和运行一个项目,但实际上我无法调试它。调试器在vsCode中启动,但所有的c++17功能都是红色的歪歪扭扭的,这些行永远无法正常执行。我猜这是我的launch.json的问题,但我不知道我缺少了什么。。。

我正在运行windows10,下面是vsCode:中的相关配置

tasks.json:

{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe",
"args": [
"-std=c++17",
"-g",
"${fileDirname}\*.cpp",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Generated task by Debugger"
}
],
"version": "2.0.0"

}

launch.json:

{
// 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": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\${fileBasenameNoExtension}.exe",
"args": ["-std=c++17"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\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"
}
]
}

Welp-答案不多,但当我只使用cl.exe而不是gcc作为编译器时,问题就不会发生。在尝试了大约一个小时后,我才停止在这个项目中使用gcc。

https://code.visualstudio.com/docs/cpp/config-msvc

最新更新