首页 > 解决方案 > 如何设置 VSCode 调试器以使用 cmake?

问题描述

我在这里发现了一个非常接近的问题,但是从那时起 C++ 扩展已经更新launch.json,为您创建的文件非常不同,我不知道如何设置它。网上也没有很多信息可以做到这一点,所以我希望有人以前做过。我目前的项目结构是这样的:

MainProj
   ./build
   CMakeLists.txt
   main.cpp
   otherClasses.hpp

build运行后..cmake出现的cmake目标make被调用Main

启动.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++ build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "g++ build active file",
      "miDebuggerPath": "/usr/bin/gdb"
    }
  ]
}

这是另一个问题的 tasks.json 文件

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "cd build && cmake .. && make"
        }
    ]
}

标签: c++visual-studio-codecmake

解决方案


推荐阅读