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.
- Have I successfully installed the packages? I can run them on bash, but vscode doesn't seem to recognize this.
- 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
评论:
lighthousecookie:
jh125486: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" }
lighthousecookie:On Ubuntu I would use “godeb” to install Go. My gut is saying that $GOROOT is not right.
pdffs:$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
I suspect your difficulties are all related to snap, but unfortunately, I don't have much experience with it.
