Help using Go in vscode

blov · · 645 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>EDIT: Solved, see my comment below.</p> <hr/> <p>I am trying to compile go-ethereum. I am using kubuntu 17.10 amd64 and have installed go and vscode using snap:</p> <pre><code>sudo snap install --classic go sudo snap install --classic vscode </code></pre> <p>I have installed the go extension recommended by vscode. I have configured vscode in the following settings:</p> <pre><code>{ &#34;git.path&#34;: &#34;/usr/bin/git&#34;, &#34;editor.wordWrap&#34;: &#34;on&#34;, &#34;go.gopath&#34;: &#34;/home/aerhv/go&#34; } </code></pre> <p>Also, the location of go:</p> <pre><code>$ which go /snap/bin/go </code></pre> <p>$GOBIN contains the binaries dlv, gocode, godef, godoc, golint, go-outline, gopkgs, goreturns, and go-symbols.</p> <p>The output of my go env is:</p> <pre><code>GOARCH=&#34;amd64&#34; GOBIN=&#34;/home/aerhv/go/bin&#34; GOCACHE=&#34;/home/aerhv/.cache/go-build&#34; GOEXE=&#34;&#34; GOHOSTARCH=&#34;amd64&#34; GOHOSTOS=&#34;linux&#34; GOOS=&#34;linux&#34; GOPATH=&#34;/home/aerhv/go&#34; GORACE=&#34;&#34; GOROOT=&#34;/snap/go/1473&#34; GOTMPDIR=&#34;&#34; GOTOOLDIR=&#34;/snap/go/1473/pkg/tool/linux_amd64&#34; GCCGO=&#34;gccgo&#34; CC=&#34;gcc&#34; CXX=&#34;g++&#34; CGO_ENABLED=&#34;1&#34; CGO_CFLAGS=&#34;-g -O2&#34; CGO_CPPFLAGS=&#34;&#34; CGO_CXXFLAGS=&#34;-g -O2&#34; CGO_FFLAGS=&#34;-g -O2&#34; CGO_LDFLAGS=&#34;-g -O2&#34; PKG_CONFIG=&#34;pkg-config&#34; GOGCCFLAGS=&#34;-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build085018022=/tmp/go-build -gno-record-gcc-switches&#34; </code></pre> <p>Now, whenever I open a .go file, vscode notifies me to install the packages that I mentioned above contained in $GOBIN.</p> <ol> <li>Have I successfully installed the packages? I can run them on bash, but vscode doesn&#39;t seem to recognize this.</li> <li>Have I missed something? I remember this setting working before but not using snap package manager, I was using apt before.</li> </ol> <p>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 :)</p> <hr/>**评论:**<br/><br/>lighthousecookie: <pre><p>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.</p> <p>The solution is to change the workspace setting from:</p> <pre><code>{ &#34;go.gopath&#34;: &#34;$GOPATH&#34; } </code></pre> <p>to:</p> <pre><code>{ &#34;go.gopath&#34;: &#34;/home/aerhv/go&#34; } </code></pre></pre>jh125486: <pre><p>On Ubuntu I would use “godeb” to install Go. My gut is saying that $GOROOT is not right. </p></pre>lighthousecookie: <pre><p>$GOROOT points to /snap/go/1473 with the following contents:</p> <pre><code>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 </code></pre> <p>Is this correct? If $GOROOT&#39;s contents aren&#39;t supposed to be like these, then please enlighten me</p></pre>pdffs: <pre><p>I suspect your difficulties are all related to snap, but unfortunately, I don&#39;t have much experience with it.</p></pre>

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

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