将GO构建适配到不同的操作系统中。

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

Adapt GO build into different OS

问题

我需要评估构建一个可在不同操作系统上运行的命令行工具的需求,如何在命令行工具(如Cloud Foundry CLI)中实现这一点?GO语言如何处理适应不同操作系统的问题?

英文:

I need to evaluate 'GO' for my requirement of building a CLI tool which should be runnable in different OS s. How is this achieved in the CLI tools such as 'Cloud Foundry CLI'?
How does GO handle this adaption into OSs?

答案1

得分: 2

Go可以从任何操作系统构建到任何操作系统。您可以使用两个环境变量GOOSGOARCH来控制操作系统和架构。前者是操作系统,后者是CPU架构。

构建64位Linux的设置如下:

GOARCH=amd64
GOOS=linux

GOARCH的选项有386, amd64arm

GOOS的选项有darwin, dragonfly, freebsd, linux, netbsd, openbsd, plan9, solariswindows

启用交叉编译还需要一些额外的步骤,详细说明可以在这里找到:http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go

英文:

Go can build from any OS to any OS. You control the OS and architecture with two environment variables, named GOOS and GOARCH. The former is the operating system, and the latter is the CPU architecture.

Building for 64-bit Linux is set as:

GOARCH=amd64
GOOS=linux

The options for GOARCH are 386, amd64 and arm.

The options for GOOS are darwin, dragonfly, freebsd, linux, netbsd, openbsd, plan9, solaris and windows

There are a few more steps to enabling cross compilation, they are described in more detail here: http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go

huangapple
  • 本文由 发表于 2015年5月3日 21:35:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/30014421.html
匿名

发表评论

匿名网友

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

确定