c++ VSCode调试工具未启动

qncylg1j  于 2022-11-27  发布在  Vscode
关注(0)|答案(2)|浏览(233)

我正在用VSCode编写一个C++程序。但是,当我按下F5键时,它所做的只是构建项目。我尝试用VSCode创建另一个简单的项目,看看它是否能工作,但没有成功。下面是我的迷你程序
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": "C/C++: clang++ build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "lldb",
        "preLaunchTask": "C/C++: clang++ build active file"
      }
    ]
  }

tasks.json

{
    "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"
}

main.cpp

#include <iostream>

int main() {
    int sum = 0;
    for (int i = 0; i < 100; i++) {
        sum += i;
        std::cout<<"Sum: " << sum << std::endl;
    }
    return 0;
}

我试着重新安装VSCode,但没有成功。当我试着调试python脚本时,它工作得很好,所以问题只出在C上。我该如何调试这个调试错误?澄清:我没有从调试器中得到错误。相反,C的调试器根本没有启动。

kwvwclae

kwvwclae1#

相反,C++调试器根本不启动。
因为launch.json中缺少调试器的路径。请在miDebuggerPath中添加调试器的路径。

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++: clang++ build and debug active file",
      .
      .
      "miDebuggerPath": "/path/to/gdb"
    }
  ]
}

或者,您可以使用“添加配置”按钮(在launch.json中可见)设置新的调试配置。

qxsslcnc

qxsslcnc2#

您可以执行以下步骤,看看它是否工作:

  • 不要忘记在运行之前用“ctrl + s”保存文件。
  • 包括c++“bin”文件夹路径到您的环境变量,则vs代码会自动检测c++调试器。
  • 在vs代码上安装代码运行器扩展。

请分享您的结果..

相关问题