Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to start debugger for c++ in visual studio code

I just switch from Netbeans to visual studio code, and i cannot debug c++, the error was Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path.... I tried to follow the c/c++ debug guide from visual studio code website that i searched from google, but it failed to run the application, but i can compile c++ from Ctrl + Shift + B so my task.json file is correct, so here are my task.json file and launch.json file.

{
    //Task.json
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "args": ["-pipe", "-std=c++14", "${fileBasename}", "-lm"],
    "showOutput": "always"
}

//Launch.json
"version": "0.2.0",
"configurations": [
    {
        "name": "C++ Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceRoot}/a.out",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "environment": [],
        "externalConsole": true,
        "linux": {
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        "osx": {
            "MIMode": "lldb"
        },
        "windows": {
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    },
like image 293
shadowlegend Avatar asked Jun 21 '26 23:06

shadowlegend


1 Answers

I just fixed it by doing the following (under windows)

  1. Installed TDM-GCC MinGW Compiler from https://sourceforge.net/projects/tdm-gcc/?source=typ_redirect use default installation path options.

  2. Added these folders to PATH environment variable

C:\TDM-GCC-64\bin

C:\TDM-GCC-64\gdb64\bin

  1. In your launch.json add the path to gdb debugger, your windows section should look like the code below
 "windows": {
                "MIMode": "gdb",
                "miDebuggerPath": "C:/TDM-GCC-64/gdb64/bin/gdb.exe",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
  1. Restart Visual Studio Code and try compile (ctrl+shift+b) and run the debugger (f5)

Remark: Like others had mentioned you should add the -g option in your tasks.json args so that the executable will be built with debugging information.

like image 52
Rayee Roded Avatar answered Jun 23 '26 11:06

Rayee Roded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!