'Why when I create launch.json file in VScode, it is empty?

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?



Solution 1:[1]

These steps helped me:

  1. Go to your launch.json file and press the "Add Configuration" button img 1

  2. Choose "C/C++: (gdb) Launch" img 2

  3. Change this line:

    "program": "enter program name, for example ${workspaceFolder}/a.out"

    to this:

    "program": "${fileDirname}/${fileBasenameNoExtension}" I took it from this tutorial

Solution 2:[2]

When I learned the tutorial video, meet the same problem. And I already spent all day solving it but failed. (video tutorial click "create launch.json" will generate complete a launch.json, but I am not. I have already searched this problem in all Chinese communities, but have not found a great answer)

Solution 3:[3]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 hungyu
Solution 3