如何在vscode中调试golang

9gm1akwq  于 12个月前  发布在  Go
关注(0)|答案(2)|浏览(123)

平台:windows 10 golang版本:go1.21.1 windows/amd 64 dlv版本:Delve编辑器版本:1.21.1
启动json:

"version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${fileDirname}"
        }
    ]

当我用vscode开始调试时,它显示:
DAP服务器侦听于:127.0.0.1:48323构建错误:运行build -o xxxx\project\rpc\client\src__debug_bin3964848569.exe -gcflags all=-N -l。客户端.go:4:2:包fmt不在std(C:\Users\Admin\go\src\fmt)客户端中。go:5:2:包net/rpc不在std(C:\Users\Admin\go\src\net\rpc)包rpc/client/src中:找不到包(退出状态% 1)
但项目可以建设成功。我是怎么解决这个问题的?谢谢
但项目可以建设成功。我是怎么解决这个问题的?谢谢

xxb16uws

xxb16uws1#

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}",
            "args": [
                "-o", "output.log"
            ]
        }
    ]
}
6yt4nkrj

6yt4nkrj2#

在打开你的vs代码后,点击main.go文件或者一个包名为(packagemain)的文件,然后启动你的调试器。
链接了解更多详情。

相关问题