Last Updated: February 25, 2016
· jbowles

Build go cross compile on OS 10.9

This is variable to go release cycle, go versions and package support, as well as Apple's gcc and llvm compiling. Most of this is adapted from Paul Crawford's 'Go Cross Compilation on Mavericks' and goxc package README.

Apple gcc support

brew update
brew tap homebrew/dupes
brew install apple-gcc42
cd /usr/bin
sudo mv gcc gcc_mavericks
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 gcc

Asking for gcc should return i686-apple-darwin11-gcc-4.2.1: no input files.

Go build from source

In this case I'll build latest release candidate for easier support from the goxc package; see the note in README about using go1.2rc5. Otherwise, I've noted where the stable current release would used.

curl https://go.googlecode.com/archive/go1.2rc5.zip  #point to stable current
tar -zxvf go1.2rc5.zip  #untar stable current
cd go-b3d5a20b070a/src  #normally this would be stable current
./all.bash  #build go

If using non-current release the path to go binary in that specific release needs to be added. Otherwise, the path would look something like export PATH=$PATH:/Users/jbowles/go/bin or wherever you built go.

go version

Asking for the Go version should return go version go1.2rc5 darwin/amd64 #or whatever version was built.

Don't forget to install common go tools: see go tools repo or specific command line tools source. Then install the goxc package

go get code.google.com/p/go.tools/cmd/godoc  #documentation tool 
go get github.com/laher/goxc  #get goxc package
goxc -t  #compile against supported platforms

What goxc -t does can be found in detail on the github page, but basically it compiles and builds the complete toolchain for ALL go supported platforms.

On the most recent build this includes packages, commands, compilers, and Go bootstrap tool

  • for host, darwin/amd64
  • for darwin/386
  • for linux/386
  • for linux/amd64
  • for linux/arm
  • for freebsd/386
  • for freebsd/amd64
  • for freebsd/arm
  • for openbsd/386
  • for openbsd/amd64
  • for windows/386
  • for windows/amd64
  • for netbsd/386
  • for netbsd/amd64
  • for netbsd/arm
  • for plan9/386

And looking in /Users/jbowles/go-b3d5a20b070a/bin we find:

Binary Installs


I've used a custom Go branch to illustrate this, so working back from the custom example to the more standard stable release should be easy.