为什么go install将二进制文件写入src目录中?

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

Why is go install writing binary in the src directory?

问题

我在目录中有一个小的Go程序:

~/gocode/src/github.com/elviejo79/goexample/

当我执行

go install

程序确实编译了,但是它将可执行文件留在了与代码相同的目录中。

但是根据如何编写Go代码,实际上应该将二进制文件保存在

~/gocode/bin

这是我的$GOPATH

$ echo $GOPATH
/home/agarcia/gocode
英文:

I have a small go program in the directory:

~/gocode/src/github.com/elviejo79/goexample/

When I execute

go install

The program does compile but it leaves the executable in the same directory as the code.

but according to How to Write Go Code the binary should in fact be saved at

~/gocode/bin

this my $GOPATH

$ echo $GOPATH
/home/agarcia/gocode

答案1

得分: 5

无法重现这个问题。请执行以下命令:

 $ go env

并验证你的 GOBIN 指向的位置。例如,在我当前的机器上,它显示为:

09:01 myname@tux64:~$ go env
GOARCH="amd64"
GOBIN="/home/myname/bin"
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myname"
GOROOT="/home/myname/go"
GOTOOLDIR="/home/myname/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
09:01 myname@tux64:~$ 

go 工具应该将二进制文件发送到 $GOBIN。在这里它是这样工作的。

英文:

Cannot reproduce this. Please Enter

 $ go env

And verify where your GOBIN points to. For example, at the machine I'm right now, it says

09:01 myname@tux64:~$ go env
GOARCH="amd64"
GOBIN="/home/myname/bin"
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myname"
GOROOT="/home/myname/go"
GOTOOLDIR="/home/myname/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
09:01 myname@tux64:~$ 

The go tool should send the binary to $GOBIN. Here it works like that.

huangapple
  • 本文由 发表于 2013年1月31日 15:46:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/14620813.html
匿名

发表评论

匿名网友

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

确定