Role: For example, you have a Mac system on hand, and your users have Linux and Windows, and they want to use it, you can cross-compile the executable files on Linux and Windows to give them
(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
(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
Transferred from: HTTP://STUDYGOLANG.COM/TOPICS/21
Cross-platform compilation Go Program (Cross compilation)