I am trying to cross-compile a go app on OSX to build binaries for windows and linux. I have read everything what I could find on the net. Closest example that I have found has been published on (apart from many unfinished discussions on go-nuts mailing list):
http://solovyov.net/en/2012/03/09/cross-compiling-go/
yet it does not work on my installation. I have go 1.0.2. As 1.0.2 is quite recent it looks to me that all above examples do not apply to this version.
Tried to do ./make.bash --no-clean
with ENV vars set to 386/windows, it does build go, however it builds go for my installation which is darwin/amd64
and completely ignores what is set in ENV that suppose to build different compiler.
Any advises how it can be done (if it can be done at all)?
Best Answer
With Go 1.5 they seem to have improved the cross compilation process, meaning it is built in now. No
./make.bash
-ing orbrew
-ing required. The process is described here but for the TLDR-ers (like me) out there: you just set theGOOS
and theGOARCH
environment variables and run the go build.For the even lazier copy-pasters (like me) out there, do something like this if you're on a *nix system:
You even learned the
env
trick, which let you set environment variables for that command only, completely free of charge.