Reputation: 439
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.
Upvotes: 10
Views: 26668
Reputation: 209
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.
Upvotes: 12
Reputation: 3997
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
Upvotes: 1