我正在使用Visual Studio代码来编写一些代码。 昨天一切正常,但现在我不能运行debugging器或build立在VS代码。
我在Windows 10上,我使用Powershell作为我的terminalselect。
我得到以下错误:
go: GOPATH entry is relative; must be absolute path: "/Users/efronlicht/go". For more details see: 'go help gopath' exit status 2 Process exiting with code: 1
这是一个特定于VS-CODE的错误,因为我可以像往常一样通过terminal来构buildgo源文件。
这里是go env的结果:
set GOARCH=amd64 set GOBIN= set GOEXE=.exe set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\work\go set GORACE= set GOROOT=C:\Go set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64 set GCCGO=gccgo set CC=gcc set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 set CXX=g++ set CGO_ENABLED=1 set PKG_CONFIG=pkg-config set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2
正如你所看到的,我的GOPATH是一个绝对的path,而不是相对的path。
我在Windows 10上使用VSCode 1.13.1,并且启动或调试时没有任何问题。
启动涉及您的工作区${workspaceroot}/.vscode/tasks.json文件。
为了确保GOPATH的价值,我的包括:
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "build", "isShellCommand": true, "showOutput": "always", "tasks": [ { "options": { "env": { "GOROOT": "D:/prgs/go/latest", "GOPATH": "${workspaceRoot}" } }, "echoCommand": false, "taskName": "install", "isBuildCommand": true },
你可以用C:/work/go来代替"${workspaceRoot}" 。
这样,一个Ctrl + Shift + B触发编译+安装( go install )
调试器涉及:
dlv.exe ${workspaceroot}/.vscode/launch.json文件 这是我的
{ "version": "0.2.0", "configurations": [ { "stopOnEntry": false, "cwd": "${workspaceRoot}", "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${fileDirname}", "env": { "GOPATH": "${workspaceRoot}" }, "args": [], "showLog": true } ] }
你可以用C:/work/go代替"${workspaceRoot}" (在GOPATH和cwd )。
请注意,我指定GOPATH 以及 cwd(当前工作目录)我打开我的文件相对从工作区的根(这样,断点被识别)。 main.go一个简单的F5运行成功(在Windows上)
这样,我就可以从一个没有GOROOT或GOPATH的cmd Windows shell启动VSCode,它仍然可以工作。 (因为我的本地用户设置包含"go.goroot": "D:/prgs/go/latest" )
如果要从tmux shell的命令行启动VSCode,请尝试在tmux之外启动。 也尝试从启动器启动。 MacOS上tmux和VSCode的变化最近让我头痛,最近又遇到了类似的问题。