doubi1797 2017-06-13 21:26
浏览 616
已采纳

Gopath环境错误

I'm using Visual Studio code to write some go code. Everything was working fine yesterday, but now I can't run the debugger or build in VS-Code.

I am on Windows 10, and I use Powershell as my terminal of choice.

I get the following error:

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

This is a VS-CODE specific error, because I can build go source files with go build through the terminal as usual.

Here are the results of 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

As you can see, my GOPATH is an absolute path, not a relative one.

  • 写回答

2条回答 默认 最新

  • douxian1923 2017-06-17 04:30
    关注

    I use VSCode 1.13.1 on Windows 10, and I launch or debug without any issue.

    Launching involves in your workspace a ${workspaceroot}/.vscode/tasks.json file.
    To be sure of the GOPATH value, mine includes:

    {
        // 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
            },
    

    You can replace "${workspaceRoot}" by C:/work/go in your case.
    That way, a <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd> triggers a compilation+installation (go install)

    And the debugger involves:

    • having a dlv.exe in the %PATH%
    • a ${workspaceroot}/.vscode/launch.json file

    Here is mine

    {
        "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
            }
        ]
    }
    

    Again you can replace "${workspaceRoot}" by C:/work/go in your case (both in GOPATH and cwd).

    Note that I specificy GOPATH as well as cwd (current working directory) I open my file relative from the workspace root (that way, the breakpoints are recognized). A simple <kbd>F5</kbd> from main.go does run delve successfully (on Windows!)

    With that, I can launch VSCode from a cmd Windows shell which has no GOROOT or GOPATH set, and it still works. (because my local user settings do include "go.goroot": "D:/prgs/go/latest")

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元