Home > front end >  Why when I create launch.json file in VScode, it is empty?
Why when I create launch.json file in VScode, it is empty?

Time:04-05

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?

CodePudding user response:

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

CodePudding user response:

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)

  • Related