Reputation: 71
I am trying to use VScode for c++ programming and I wanted to learn debugging. When in run and debug section I click the link create a launch.json file, it is created, but almost empty - particularly "configurations" are empty. It looks like this:
{
// 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": []
}
What do I need to do differently, or do I need to change some settings?
I remember before it created a launch.json file with some configuration, since then I changed compiler path to msys2/mingw64/bin/g++.exe, don't know if that may have caused the problem.
EDIT: I made it work by copy-pasting the right configuration somewhere from the internet:
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\msys2\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
However the question still remains. I followed a tutorial. The steps are "create a launch.json file", then select an environment: C++ (GDB/LLDB), and then select a configuration (should be "g++.exe - build and debug active file") but it does not offer me this last option, why?
Upvotes: 6
Views: 16703
Reputation: 11
I also had that problem. I think the problem is with the "C/C++ for Visual Studio Code".
1.Open the "C/C++ for Visual Studio Code" extension page
2.Click on the the dropdown button beside "Uninstall button"
3.Click on the "Install another version" https://i.sstatic.net/DaClo.png
4.Intall a previous version
--> this worked for me
Upvotes: 1
Reputation: 11
Had similar problem and I've spent several hours to solve (please note i am using linux). Any action on "launch.json" file had zero effect. The only thing helped was to re-install "VS Code". (trivially simple =) ) Install 'snap' if You don't have it through the terminal.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install snap
And then re-install code.
sudo snap install --classic code
After taking actions above, "launch.json" has been created automatically by VS Code and it is working normally. Just FYI it was not working properly after re-installing by any other way in my case. Only 'snap' had worked. Hope that would be helpful for somebody.
Idea to re-install with 'snap' had come after watching this video. https://www.youtube.com/watch?v=BEJUdkPemYY
Upvotes: 1
Reputation: 51
These steps helped me:
Go to your launch.json file and press the "Add Configuration" button img 1
Choose "C/C++: (gdb) Launch" img 2
Change this line:
"program": "enter program name, for example ${workspaceFolder}/a.out"
to this:
"program": "${fileDirname}/${fileBasenameNoExtension}" I took it from this tutorial
Upvotes: 5