<p>Hi all,</p>
<p>Here is an example project:</p>
<pre><code>$GOPATH/src/project:
- foo
|- main.go
- bar
|- main.go
</code></pre>
<p>If I cd into foo/, run <em>go build</em>, it prodices <em>foo</em> binary in the foo/ directory. The same for bar.</p>
<p>But, if I run "go build -v ./..." in the project's root, I get the following output, and have no binaries:</p>
<pre><code>$ go build -v ./...
project/bar
project/foo
$ find .
.
./bar
./bar/main.go
./foo
./foo/main.go
</code></pre>
<p><em>go build ./...</em> for subdirs produces no binaries at all.
<em>go help packages</em> do not help to understand it.</p>
<p>So, is it designed to be like that on purpose?</p>
<p>EDIT: found in go help build:</p>
<blockquote>
<p>When the command line specifies a single main package,
build writes the resulting executable to output.
Otherwise build compiles the packages but discards the results,
serving only as a check that the packages can be built.</p>
</blockquote>
<hr/>**评论:**<br/><br/>: <pre><p>[deleted]</p></pre>divan0: <pre><p>Well, I'm aware of go install ./..., but the point is 'go build' command is a synonym for 'compile and get binary in current dir', so I do expect the same when I run with ./...</p>
<p>Now, I see in <em>go help build</em> this behavior is described, but I still wonder why it's made so. Why not build binaries for multiple packages as well on <em>go build ./...</em>?</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传