debugging 如何 在 macOS 上 调试 vscode 中 的 c + + 文件 ?

x33g5p2x  于 2022-11-14  发布在  Mac
关注(0)|答案(1)|浏览(289)

我一直在尝试在vscode中调试.cpp文件,以下文件已正确安装。(我已通过code-runner extension运行了.cpp文件,但现在我想调试c++文件。)

$ clang --version // or g++ --version (both same result)

Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

我已经单击了调试按钮并尝试了列出的所有编译器

  • C/C++: clang++ build and debug active file
  • C/C++: clang build and debug active file
  • C/C++: g++ build and debug active file
  • C/C++: cpp build and debug active file

但每次尝试我都遇到以下结果:

Build finished successfully.
 *  Terminal will be reused by tasks, press any key to close it.

或错误消息

The preLaunchTask 'C/C++: g++ build active file' terminated with exit code -1.

有没有其他方法可以在macOS上的vscode中调试c++文件?

我的tasks.json文件(我的c++文件位于项目根目录中)

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

我的launch.json档案

{
    "configurations": [
        {
            "name": "C/C++: clang build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: clang build active file"
        }
    ],
    "version": "2.0.0"
}
30byixjq

30byixjq1#

json“预启动任务”:“C/C++:clang生成活动文件”
使用task.json“标签”:“C/C++:clang生成活动文件”作为其执行任务
因此应该修改launch.json
请注意将clang更改为clang
以匹配任务标签

{
    "configurations": [
        {
            "name": "C/C++: clang build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: clang++ build active file"
        }
    ],
    "version": "2.0.0"
}

相关问题