Golang: How to cross compile on Linux for Windows

To build from Linux to Windows, you need to set the environment variables GOOS to Windows and GOARCH to amd64.

On Bash or ZSH:

% GOOS=windows GOARCH=amd64 go build
  • For more details see: https://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
  • A description of possible values for GOOS and GOARCH is available here: https://golang.org/doc/install/source#environment

If your package requires CGO then you need to use the mingw-w64 compiler:

sudo apt-get install gcc-multilib
sudo apt-get install gcc-mingw-w64

GOOS=windows GOARCH=386 \
  CGO_ENABLED=1 CXX=i686-w64-mingw32-g++ CC=i686-w64-mingw32-gcc \
  go build

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)