go install命令无法识别”-o”标志。

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

go install does not recognize "-o" flag

问题

我正在尝试使用-o标志进行go install并重命名输出文件。

go install -o bar.exe src/foo.go

但是这会导致以下错误:

flag provided but not defined: -o
usage: install [build flags] [packages]

go help build显示-o是正确的构建标志来重命名输出二进制文件。没有提到这个标志在go install中未定义。

go run -o bar.exe src/foo.go也会导致相同的错误。

go build -o bar.exe src/foo.go可以正常工作。我得到了bar.exe。

所以这只是文档错误,还是我漏掉了什么?

我的版本是:go1.5 windows/386

谢谢。

英文:

I'm trying to do a go install and rename the output with the -o flag.

go install -o bar.exe src/foo.go

But this fails with the error:

flag provided but not defined: -o
usage: install [build flags] [packages]

go help build shows -o as the correct build flag to rename the output binary. There is no mention that this flag is not defined for go install.

go run -o bar.exe src/foo.go fails with the same error.

go build -o bar.exe src/foo.go works. I get bar.exe.

So is this just an error of documentation, or have I missed something?

My version: go1.5 windows/386.

Thanks.

答案1

得分: 48

go build 命令接受 -o 标志,但 go install 命令不接受。

go install 命令总是将输出到 $GOPATH/bin 目录。

如果你想将自定义的二进制文件名安装到你的 GOPATH 中,可以使用 go build -o $GOPATH/bin/whatever 命令,这大致等同于 go install

英文:

go build accepts the -o flag but go install does not.

go install will always output to $GOPATH/bin

If you want to install a custom binary name to your gopath you can do go build -o $GOPATH/bin/whatever and that will be roughly equivalent to go install

答案2

得分: 0

你可以伪造-o标志,如果你只关心位置而不关心二进制文件的名称。为安装命令定义GOBIN

GOBIN=`readlink -f my/location` go install some/persons/go-package

注意:这对于交叉编译的二进制文件无效。

英文:

You can fake the -o flag, if all you care about is the location, and not the name of the binary. Define GOBIN for the install command:

GOBIN=`readlink -f my/location` go install some/persons/go-package

Caveat: This doesn't work for cross-compiled binaries.

huangapple
  • 本文由 发表于 2015年10月21日 01:55:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/33243532.html
匿名

发表评论

匿名网友

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

确定