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

Ame*_*Bel 2 go

godocgotour可以通过从其指定的源目录构建和运行go build。什么是gotour二进制文件而创建一个二进制文件go get却不是这样的原因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
....
Run Code Online (Sandbox Code Playgroud)

icz*_*cza 5

Godoc非常特别,因为它是Go发行版中的官方工具。

因此,如果您使用go getgodoc,结果二进制文件将不会放置在$GOPATH/bin所有其他可执行文件所在的位置,而是$GOROOT/bin

Gotour以这种方式并不特殊,因此它已安装到您的中$GOPATH/bin


Gim*_*ima 5

而对于那些只是godoc$GOPATH可以这样做:


1.下载,不要安装:

$ go get -u -d golang.org/x/tools/cmd/godoc
Run Code Online (Sandbox Code Playgroud)

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

$ go build -o $GOPATH/bin/godoc golang.org/x/tools/cmd/godoc
Run Code Online (Sandbox Code Playgroud)