| # Building windows go programs on linux |
| I use linux/386, but, I suspect, this procedure will apply to other host platforms as well. |
| First step is to build host version of go: |
| sudo -E GOOS=windows GOARCH=386 PATH=$PATH ./make.bash |
| Next you need to build the rest of go compilers and linkers. I have small program to do that: |
| go tool dist install -v cmd/$arch$cmd |
| Last step is to build windows versions of standard commands and libraries. I have small script for that too: |
| echo 'GOOS is not specified' 1>&2 |
| if [ "$GOOS" = "windows" ]; then |
| go tool dist install -v pkg/runtime |
| $ ~/bin/buildpkg windows 386 |
| to build windows/386 version of Go commands and packages. You can, probably, see it from my script, I exclude building of any cgo related parts - these will not work for me, since I do not have correspondent gcc cross-compiling tools installed. So I just skip those. |
| Now we're ready to build our windows executable: |
| $ GOOS=windows GOARCH=386 go build -o hello.exe hello.go |
| We just need to find Windows computer to run our hello.exe. |