I saw a thread on cross-compilation in golang-nuts group recently and decided to replicate information here so I won’t forget and (maybe/hopefully) it’ll make it easier to discover for others how to cross-compile go applications.
I’m on OS X and my Go source code resides in
~/var/go. In this case what I do
> cd ~/var/go/src > CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./make.bash > CGO_ENABLED=0 GOOS=windows GOARCH=amd64 ./make.bash
And afterwards in different directory:
> CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gr-linux64 goreplace > CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gr-win64 goreplace
This has some limitations - you can’t cross-compile applications, which
are using CGo. In particular this means applications importing package
net. Which is a shame, but still, cross-compilation has never been
UPD. Also see comment on reddit for more.
UPD. In case you miss something, there is a question on StackOverflow with different wording, which may help.