Help using Go in vscode

blov · 2018-04-02 08:30:12 · 803 次点击    
这是一个分享于 2018-04-02 08:30:12 的资源,其中的信息可能已经有所发展或是发生改变。

EDIT: Solved, see my comment below.


I am trying to compile go-ethereum. I am using kubuntu 17.10 amd64 and have installed go and vscode using snap:

sudo snap install --classic go
sudo snap install --classic vscode

I have installed the go extension recommended by vscode. I have configured vscode in the following settings:

{
    "git.path": "/usr/bin/git",
    "editor.wordWrap": "on",
    "go.gopath": "/home/aerhv/go"
}

Also, the location of go:

$ which go
/snap/bin/go

$GOBIN contains the binaries dlv, gocode, godef, godoc, golint, go-outline, gopkgs, goreturns, and go-symbols.

The output of my go env is:

GOARCH="amd64"
GOBIN="/home/aerhv/go/bin"
GOCACHE="/home/aerhv/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/aerhv/go"
GORACE=""
GOROOT="/snap/go/1473"
GOTMPDIR=""
GOTOOLDIR="/snap/go/1473/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build085018022=/tmp/go-build -gno-record-gcc-switches"

Now, whenever I open a .go file, vscode notifies me to install the packages that I mentioned above contained in $GOBIN.

  1. Have I successfully installed the packages? I can run them on bash, but vscode doesn't seem to recognize this.
  2. Have I missed something? I remember this setting working before but not using snap package manager, I was using apt before.

fyi I have googled and stackoverflow-ed to no avail. The solutions provided seem to work on them but not on my case, I have no idea why. Please help thank you in advance :smile:


评论:

lighthousecookie:

I have solved the problem. GOPATH must be set to an absolute path, not relative. While all of my settings follows it, my workspace settings on vscode was set to relative.

The solution is to change the workspace setting from:

{ "go.gopath": "$GOPATH" }

to:

{ "go.gopath": "/home/aerhv/go" }
jh125486:

On Ubuntu I would use “godeb” to install Go. My gut is saying that $GOROOT is not right.

lighthousecookie:

$GOROOT points to /snap/go/1473 with the following contents:

api                    CONTRIBUTING.md  gowrapper  PATENTS     src
AUTHORS                CONTRIBUTORS     lib        pkg         test
bin                    doc              LICENSE    README.md   VERSION
command-gofmt.wrapper  favicon.ico      meta       robots.txt
command-go.wrapper     gofmtwrapper     misc       snap

Is this correct? If $GOROOT's contents aren't supposed to be like these, then please enlighten me

pdffs:

I suspect your difficulties are all related to snap, but unfortunately, I don't have much experience with it.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

803 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传