Reference: HTTP://STUDYGOLANG.COM/TOPICS/21
(1) First enter the GO/SRC source directory, execute the following command to create the target platform required package and tool files.
$ cd/usr/local/go/src
$ cgo_enabled=0 goos=linux goarch=amd64./make.bash
If it is Windows, you can modify GOOS.
$ cgo_enabled=0 goos=windows goarch=amd64./make.bash
----------------------------------------------------------------------------
There may be an error here:
##### Building Go Bootstrap tool.
Cmd/dist
ERROR: $GOROOT _bootstrap must not being set to $GOROOT
Set $GOROOT _bootstrap to a working go tree >= go 1.4.
Workaround:
Copy the current go to a share
#cp-RF Go go1.4
----------------------------------------------------------------------------
(2) The executable files required for Linux and Windows platforms can now be compiled.
$ cgo_enabled=0 goos=linux goarch=amd64 Go Build
$ cgo_enabled=0 goos=windows goarch=amd64 Go Build
However, this approach does not support CGO for the time being.
http://solovyov.net/en/2012/03/09/cross-compiling-go/
The above assumptions are 64-bit architecture, 32-bit, modified Goarch to 386
Description
This is not to recompile go, because when you install go, you just compile what your local system needs, and cross-platform compilation requires more support for other platforms in go. So, there is./make.bash such a process
Cross-compilation issues supplement:
First, it is recommended to install the go language through the source installation, otherwise there may be no make.bash or Make.bat program.
The above steps need to be performed because some of the tools and platform-related code is not generated when you install the go language, and instead of reinstalling the go language, you will build the tools and files needed for cross-compilation (target platform). These are only done at the time of the first cross-compilation. After that, you don't need it.
For faster compilation, you can
./make.bash--no-clean
Go to compile Windows execution file on Linux