【问题标题】:VsCode debugging with c++17 fails?使用 c++17 进行 VsCode 调试失败?
【发布时间】:2021-03-16 02:14:19
【问题描述】:

我遇到了一个问题,我可以在启用 c++17 标志的情况下构建和运行项目,但实际上无法调试它。调试器在 vsCode 中启动,但所有 c++ 17 功能都是红色波浪线,并且这些行永远不会正确执行。我猜这是我的 launch.json 的问题,但我无法弄清楚我错过了什么......

我运行的是windows 10,下面是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"
        }
    ]
}

【问题讨论】:

    标签: c++ debugging visual-studio-code gdb


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 2021-06-07
      • 2021-10-28
      • 2017-07-31
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      相关资源
      最近更新 更多