在`go install package`期间创建几个二进制文件。

huangapple go评论132阅读模式
英文:

Creating few binaries during `go install package`

问题

go工具可以创建一个二进制文件,并将其放置在GOBIN目录中,如果包含一个main子包(或者如果包本身是一个main包)。是否有可能使用单个go install package命令创建多个(至少两个)二进制文件,而不使用GNU make来实现这个目的呢?

谢谢。

英文:

go tool can create a binary and place it to GOBIN if package contains a main sub package (or if package is a main). Is there a possibility to create a few (at least two) binaries with single go install package command? Meaning without using GNU make for this purposes.

Thank you.

答案1

得分: 3

如果所有命令都在一个共同的目录下,使用go install root/...是完全可能的。末尾的三个点告诉go命令在该目录下的所有包中执行此操作。相同的三个点符号也适用于go getgo build,以及可能的所有go命令。

如果导入路径包含一个或多个“...”通配符,则它被视为模式,每个通配符可以匹配任何字符串,包括空字符串和包含斜杠的字符串。这样的模式会扩展为在GOPATH树中找到的与模式匹配的所有包目录。作为特例,x/...不仅匹配x,还匹配x的子目录。例如,net/...会扩展为net及其子目录中的包。

http://golang.org/cmd/go/

英文:

It is definitely possible if all commands are under a common directory, using go install root/.... The trailing three dots tell the go command to do this for all packages under this directory. The same three-dots notation works for go get or go build and probably all go commands.

> An import path is a pattern if it includes one or more "..." wildcards, each of which can match any string, including the empty string and strings containing slashes. Such a pattern expands to all package directories found in the GOPATH trees with names matching the patterns. As a special case, x/... matches x as well as x's subdirectories. For example, net/... expands to net and packages in its subdirectories.

http://golang.org/cmd/go/

答案2

得分: 2

据我所知,这是不可能的。通常的做法是将你的二进制文件放入以cmd作为最后一个路径元素的包中。然后,人们可以通过以下方式安装所有的二进制文件:

go get code.google.com/p/codesearch/cmd/{cindex,csearch,cgrep}
英文:

AFAIK this is not possible. The usual convential is that you put your binaries into packages that have cmd as their last path element. People can then install all the binaries like this:

go get code.google.com/p/codesearch/cmd/{cindex,csearch,cgrep}

huangapple
  • 本文由 发表于 2013年9月26日 20:58:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/19028981.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定