How to get debugging c++ to work in VSCode on a mac?

Viewed 2002

Can someone explain how to get building and debugging to work in VSCode on a Mac?

Let's assume we successfully installed cpp tools:

enter image description here

-Including creating a proper task file that works on a mac. -The required changes to launch.json -Any other step required.

(Don't get me wrong, I'm not lazy, I have been trying for more then 2 hours now and it seems that a proper answer for this question can help a lot of people.)

2 Answers

I don't count the time I lost looking for an answer to this question!

I found the vscode-lldb extension and it works fine, all other solutions I found don't work for me.

You still have to create configuration files, here are mine to debug my unit tests:

I'm using googletest and extension c++14 in this example

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build & debug tests",
      "type": "shell",
      "command": "g++",
      "args": [
        "-g",
        "-std=c++14",
        "-I/src",
        "-lgtest",
        "tests/MainTest.cpp",
        "-o",
        "bin/testMain"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": [
        "$gcc"
      ]
    }
  ]
}

launch.json

{
  "version": "0.2.0",
  "configurations":
  [
    {
      "name": "Debug Tests C/C++",
      "type": "lldb",
      "request": "launch",
      "program": "${workspaceFolder}/bin/testMain",
      "args": [],
      "cwd": "${workspaceFolder}/tests",
      "preLaunchTask": "build & debug tests"
    }
  ]
}
Related