Golang二进制文件是否可移植? [英] Are Golang binaries portable?
本文介绍了Golang二进制文件是否可移植?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我主要是Linux用户,但我正在开发一个应用程序,我想要跨平台。我搜索了四周,但我似乎无法找到信息以免除以下内容:
- 如果我
在我的amd64 Ubuntu系统上安装
二进制文件,它还可以在其他人的 64位Ubuntu / Debian系统上工作吗? - 我如何使用
go install
来构建x86_64二进制文件,该文件也可以在32位Debianlikes上运行开箱即用? - 如果我必须使用Windows来创建一个可在Windows上运行的二进制文件,那么我怎样才能确保即使我的Windows系统是64位,可执行文件也将为x86_64构建?
- 是的,它会;基本上所有为64位Linux编译的二进制文件都是如此,不仅仅是用Go编写的二进制文件(共享库除外,Go不依赖于此)
- 您可以设置
GOOS
和GOARCH
构建之前的环境变量:GOOS = windows GOARCH = 386 go build
(或go install
或其他)等等。
- 默认情况下,运行,但这不是必需的 - 请参阅2
- 您可以设置
- If I
go install
a binary on my amd64 Ubuntu system, will it also work on anyone else's 64-bit Ubuntu/Debian system? - How can I use
go install
to build an x86_64 binary that will also run out-of-the-box on 32-bit Debianlikes? - If I must use Windows to make a binary which will run on Windows, how can I also ensure that even if my Windows system is 64-bit the executable will be built for x86_64?
- Yes it will; this is true of basically all binaries compiled for 64-bit Linux, not just those written in Go (except for shared libraries, which Go doesn't rely on)
- You can set the
GOOS
andGOARCH
environment variables before building:GOOS=windows GOARCH=386 go build
(orgo install
or whatever), etc - By default a binary will be built for the system you're running, but this isn't necessary - see 2
ol>
我的问题实际上归结为如何静态/便携是go的链接器/编译器吗?
解决方案
Suppose I'm a primarily Linux user, but I'm developing an application in Go that I want to be cross platform. I've searched around, but I can't seem to find information to absolve the following:
My questions in effect boil down to, "how static/portable is go's linker/compiler?"
解决方案
这篇关于Golang二进制文件是否可移植?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文