英文:
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可以从任何操作系统构建到任何操作系统。您可以使用两个环境变量GOOS
和GOARCH
来控制操作系统和架构。前者是操作系统,后者是CPU架构。
构建64位Linux的设置如下:
GOARCH=amd64
GOOS=linux
GOARCH的选项有386, amd64
和arm
。
GOOS的选项有darwin, dragonfly, freebsd, linux, netbsd, openbsd, plan9, solaris
和windows
。
启用交叉编译还需要一些额外的步骤,详细说明可以在这里找到: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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论