New to Go: `go build` of a package puts the binary in GO_ROOT, not GO_WORKSPACE, /pkg

agolangf · · 416 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Thanks for reading, and I hope it&#39;s an appropriate question. Windows Go, C:\go_win for install, with C:\go_win\bin on path. I&#39;ve got my workspace on X:\GO_WS\, with <code>pkg</code> <code>src</code> and <code>bin</code> all present. </p> <p>I&#39;ve worked through the hello world tutorial twice now, but I&#39;m getting my <code>go build</code> of a package installed to the C:\go_win\pkg\windows_amd64. My workspace X:\GO_WS\pkg is empty - no initialized windows_amd64 directory.</p> <p>It seems like the separation between the Workspace and &#39;primary Go&#39; install locations should be kept pretty clean - and the tutorial says my <code>stringutils.a</code> <em>should</em> be in GO_WS\pkg.</p> <p>Any thoughts?</p> <p>Thanks!</p> <p>edit: be not bin</p> <hr/>**评论:**<br/><br/>Sythe2o0: <pre><p>What tutorial is telling you about <code>GO_WORKSPACE</code>? I&#39;ve never heard of that variable before-- your workspace in Go is almost always your package inside of your <code>GOPATH</code>, and that&#39;s also where binaries will be installed: <a href="https://golang.org/doc/code.html#GOPATH" rel="nofollow">https://golang.org/doc/code.html#GOPATH</a></p></pre>nsd433: <pre><p>I&#39;m not sure what tutorial you&#39;re looking at (the 1st two hits on google for &#34;go hello world tutorial&#34; don&#39;t mention &#34;pkg&#34;), but in general only packages compile to files in <code>pkg/</code>. You&#39;re probably compiling a package named &#39;main&#39;, which isn&#39;t a real package, and doesn&#39;t show up in <code>pkg/</code>.</p></pre>carsncode: <pre><p>You can pretty much just ignore pkg entirely. It&#39;s just a cache of compiled objects, completed binaries are put into bin.</p></pre>justinisrael: <pre><p>Some of your terminology needs to be clarified if anyone is going to be able to assist you. GOROOT is the installation path of Go. You generally don&#39;t need to set this or even think about it beyond the bin/ being on your PATH. Nothing of your own projects should get installed here. GOPATH is most commonly set to a single user location as the top level directory to contain all Go source code. This is the location where you might see a pkg cache location for built libraries. Officially there is no &#34;WORKSPACE&#34; env var so this must either be confused with GOPATH or be a concept specific to a 3rd party tool or tutorial. It would be ideal for you to be specific about the details of the instructions you have followed. </p></pre>

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

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