使用1.5.x进行交叉编译时,输出文件被覆盖。

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

Go cross-compilation with 1.5.x - output file is overridden

问题

我正在使用go 1.5版本,并按照这里所指定的方式进行交叉编译。

问题是,当编译项目时,它会覆盖上一次编译创建的二进制文件。而且,我永远不会知道正在运行的可执行文件是编译到哪个操作系统/架构上的(除非是Windows)。

有没有办法在编译命令中重命名文件?

英文:

I'm using go 1.5 and I'm cross compiling like specified here.

The problem is that when compiling the project it will override the binary the last compilation created. Moreover - I will never know which OS/ARCH the executable file that I'm running was compiled to (in any case that is not windows).

Is there a way to rename the file at compile command?

答案1

得分: 2

从你提供的链接页面上可以看到:

-o 可以用来修改你的二进制文件的名称和目标位置,但要记住,go build 命令接受的值是相对于你的 $GOPATH/src 路径的,而不是你的工作目录,所以改变目录然后执行 go build 命令也是一个选择。

如果你在名称中使用 GOOSGOARCH,你应该能够实现你想要的效果。

英文:

From the page you linked to:

> -o may be used to alter the name and destination of your binary, but remember that go build takes a value that is relative to your $GOPATH/src, not your working directory, so changing directories then executing the go build command is also an option.

If you use GOOS and GOARCH in the name, you should be able to achieve what you want.

答案2

得分: 2

你可以使用"-o"参数,像这样:

GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o test/output/myapp

英文:

You could use the "-o" argument, like this:

GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o test/output/myapp

huangapple
  • 本文由 发表于 2015年11月11日 15:46:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/33646162.html
匿名

发表评论

匿名网友

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

确定