运行`go get golang.org/x/tools/cmd/godoc`时为什么没有创建二进制文件?

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

Why is there no binary created when running `go get golang.org/x/tools/cmd/godoc`?

问题

godocgotour可以通过go build从它们各自的源代码目录构建和运行。为什么在使用go get获取gotour时会创建一个二进制文件,而对于godoc则不是这样呢?

命令行输出:

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> ls

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/.gvm/pkgsets/go1.5.1/global"
GORACE=""
GOROOT="/home/user/.gvm/gos/go1.5.1"
GOTOOLDIR="/home/user/.gvm/gos/go1.5.1/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> go get golang.org/x/tools/cmd/godoc

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> ls
pkg  src

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> go get golang.org/x/tour/gotour

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> ls 
bin  pkg  src

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> ls bin/
gotour

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> cd src/golang.org/x/tools/cmd/godoc/

[ user@pc:~/.gvm/pkgsets/go1.5.1/global/src/golang.org/x/tools/cmd/godoc ]
>> go build

[ user@pc:~/.gvm/pkgsets/go1.5.1/global/src/golang.org/x/tools/cmd/godoc ]
>> ./godoc 
usage: godoc package [name ...]
	godoc -http=:6060
  -analysis string
    	comma-separated list of analyses to perform (supported: type, pointer). See http://golang.org/lib/godoc/analysis/help.html
  -ex
    	show examples in command line mode
  -goroot string
    	Go root directory (default "/home/user/.gvm/gos/go1.5.1")
  -html
    	print HTML in command-line mode
  -http string
    	HTTP service address (e.g., ':6060')
  -httptest.serve string
    	if non-empty, httptest.NewServer serves on this address and blocks
  -index
....
英文:

godoc and gotour can be built and run from their respecitve source directory with go build. What is the reason a gotour binary created when one go get it and that is not the case for godoc.

Command Line Output:

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> ls

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/.gvm/pkgsets/go1.5.1/global"
GORACE=""
GOROOT="/home/user/.gvm/gos/go1.5.1"
GOTOOLDIR="/home/user/.gvm/gos/go1.5.1/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> go get golang.org/x/tools/cmd/godoc

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> ls
pkg  src

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> go get golang.org/x/tour/gotour

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> ls 
bin  pkg  src

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> ls bin/
gotour

[ user@pc:~/.gvm/pkgsets/go1.5.1/global ]
>> cd src/golang.org/x/tools/cmd/godoc/

[ user@pc:~/.gvm/pkgsets/go1.5.1/global/src/golang.org/x/tools/cmd/godoc ]
>> go build

[ user@pc:~/.gvm/pkgsets/go1.5.1/global/src/golang.org/x/tools/cmd/godoc ]
>> ./godoc 
usage: godoc package [name ...]
	godoc -http=:6060
  -analysis string
    	comma-separated list of analyses to perform (supported: type, pointer). See http://golang.org/lib/godoc/analysis/help.html
  -ex
    	show examples in command line mode
  -goroot string
    	Go root directory (default "/home/user/.gvm/gos/go1.5.1")
  -html
    	print HTML in command-line mode
  -http string
    	HTTP service address (e.g., ':6060')
  -httptest.serve string
    	if non-empty, httptest.NewServer serves on this address and blocks
  -index
....

答案1

得分: 6

Godoc是特殊的,因为它是Go发行版的官方工具之一。

因此,如果你使用go get命令获取godoc,生成的二进制文件将不会放置在$GOPATH/bin目录下,而是放置在$GOROOT/bin目录下。

Gotour在这方面并不特殊,所以它会被安装在你的$GOPATH/bin目录下。

英文:

Godoc is special as it is an official tool being part of the Go distribution.

So if you go get godoc, the result binary will not be placed under $GOPATH/bin where all other executables go, but under $GOROOT/bin.

Gotour is not special in this way, so it gets installed into your $GOPATH/bin.

答案2

得分: 5

以下是翻译好的内容:

对于那些只想在$GOPATH下安装godoc的人可以这样做:


  1. 下载,不安装:

    $ go get -u -d golang.org/x/tools/cmd/godoc

  2. 将二进制文件构建到指定路径:

    $ go build -o $GOPATH/bin/godoc golang.org/x/tools/cmd/godoc

英文:

And for those just want to install godoc under $GOPATH can do so:


1. Download, don't install:

$ go get -u -d golang.org/x/tools/cmd/godoc

2. Build binary to specific path:

$ go build -o $GOPATH/bin/godoc golang.org/x/tools/cmd/godoc

huangapple
  • 本文由 发表于 2015年10月14日 15:06:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/33118766.html
匿名

发表评论

匿名网友

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

确定