Fathima
Fathima

Reputation: 97

Adapt GO build into different OS

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?

Upvotes: 2

Views: 198

Answers (1)

Not_a_Golfer
Not_a_Golfer

Reputation: 49195

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

Upvotes: 2

Related Questions