10

I'm trying to set up VSCode to start learning C++. As part of this, I need to be able to debug the code, so I've installed the C/C++ extension with the .vsix file to allow it to add C++ debugging configurations. However, when I try to set up a configuration, I do not see C++ as an option for environments; only node, gdb, and lldb. Following the instructions here, I do not see any suggestions for C++ in the command palette. As such, I manually setup the tasks, c_cpp_properties, and launch.json files, copying and pasting and modifying the paths as appropriate. However, VSCode labels cppdbg in launch.json as not recognized as a debug type, as well as the fields stopAtEntry, environments, MIMode, and miDebuggerPath as "Property <...> not allowed". If I change it to gdb, it recognizes the debug type, but the property not allowed error remains:

c_cpp_properties.json:

{
  "configurations": [
    {
      "name": "Win32",
      "includePath": ["${workspaceFolder}/**", "${vcpkgRoot}/x86-windows/include"],
      "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
      "windowsSdkVersion": "10.0.17763.0",
      "compilerPath": "C:\\dev\\tools\\mingw64\\bin\\g++.exe",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "${default}"
    }
  ],
  "version": 4
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "build hello world",
        "type": "shell",
        "command": "g++",
        "args": ["test.cpp"],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }

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": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/test.exe",
        "args": [],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "console": true,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\dev\\tools\\mingw64\\bin\\gdb.exe"
      }
    ]
  }

The version of VSCode I'm using is older, 1.19. The HelloWorld/test.cpp file I wrote the code to is extremely simple:

#include <iostream>
#include <string>

int main()
{
    std::cout << "Type your name" << std::endl;
    std::string name;
    std::cin >> name;
    std::cout << "Hello, " << name << std::endl;

    return 0;
}

Can anyone tell me what I'm missing in this process, as I've not been able to find anything on google so far.

0

2 Answers 2

11

In my case, I hadn't installed Microsoft C/C++ extension in vscode. I use docker container for development and I needed to install this extension after attaching to my docker container.

Sign up to request clarification or add additional context in comments.

1 Comment

How this is relevant to this question ? it is asking about c++ debug with the help of c++ extension.
1

I had that same error message, turns out I had two different configurations listed within my launch.json file. I assumed I'd just pick one during the run cycle and things would just work. Turns out I had to remark out the unused launch configuration to get rid of the error message. (gdb) Launch was fine, remark out the entire Linux version lldb

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.