VS Code 调试 Golang 出现 Failed to continue: Check the debug console for details

这是默认的launch.json,"program": "${fileDirname}" 指示从当前文件所在的目录作为go 程序的目录。

go程序是以目录为单位的,编译的时候一个文件中的全部.go都参与编译,只能有一个文件中有main函数。

如果vs code 当前打开的文件与主程序不在同一个目录下,按F5开始调试时就会报Failed to continue: Check the debug console for details 的错误。

解决办法是打开含有main函数的.go文件,在此文件为当前文档状态下,点击F5进行调试。就不会出现这个问题了。

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "env": {},
            "args": []
        }
    ]
}

另有 https://www.jianshu.com/p/663e0fcacf9b 里面修改launch.json,供参考。

"program": "${workspaceRoot}/src"

猜你喜欢

转载自blog.csdn.net/v6543210/article/details/87748101
今日推荐