go build ./... doesn't build binaries?

xuanbao · 2015-04-20 17:03:39 · 1076 次点击    
这是一个分享于 2015-04-20 17:03:39 的资源,其中的信息可能已经有所发展或是发生改变。

Hi all,

Here is an example project:

$GOPATH/src/project:
- foo
   |- main.go
- bar
   |- main.go

If I cd into foo/, run go build, it prodices foo binary in the foo/ directory. The same for bar.

But, if I run "go build -v ./..." in the project's root, I get the following output, and have no binaries:

$ go build -v ./...
  project/bar
  project/foo
$ find .
.
./bar
./bar/main.go
./foo
./foo/main.go

go build ./... for subdirs produces no binaries at all. go help packages do not help to understand it.

So, is it designed to be like that on purpose?

EDIT: found in go help build:

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.


评论:

:

[deleted]

divan0:

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 ./...

Now, I see in go help build this behavior is described, but I still wonder why it's made so. Why not build binaries for multiple packages as well on go build ./...?


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

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