简体   繁体   中英

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... Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path... 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
                }
            ]
        }
    },

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

  3. 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 } ] } 

  4. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM