This is a creation in Article, where the information may have evolved or changed.
1, download the relevant procedures.
Golang Download: http://www.golangtc.com/download
git download: http://git-scm.com/download/
TDM-GCC Download: http://tdm-gcc.tdragon.net/download
2, go to compile the environment configuration
Install TDM-GCC, the program will automatically set the PATH environment variable, if not set successfully please manually set.
Install go, you need to set the GOROOT,GOPATH,GOBIN,PATH environment variable after installation,
which
Goroot for your go installation and directory
Gopath for your Go Program development directory, the go get after the package will also be downloaded to the directory.
Gobin for your Go run directory, after running the Go Install command, the program will be installed into the directory.
Path is the root of your go program and is used to invoke the GO command from the console.
3. Configuring the Cross-compilation environment
In the Go root directory of the SRC directory, create a new BUILD.bat file, and copy the contents as follows:
Set cgo_enabled=0Set Goroot_bootstrap=c:/go::x86 block Set Goarch=386Set GOOS=Windowscall Make. bat--no-Clean set GOOS=Linuxcall Make. bat--no-Clean set GOOS=Freebsdcall Make. bat--no-Clean set GOOS=Darwincall Make. bat--no-On the x64:::::::::::.::: : ,:-:::-------:------:----:::----::: £:::::,:-:::;=Amd64set GOOS=Linuxcall Make. bat--no-For:::::::::::::::::--:::----:::---:::---:::---:::---:::---:::: goarch=Armset GOOS=Linuxcall Make. bat--no-In:::::::::::::::::-::::-::--:::-: goarch: :::::.::----:.::-=386Set GOOS=Windowsgo Get github.com/nsf/Gocodepause
My Go program version is 1.6, you need to set the Goroot_bootstrap variable to go installation directory, otherwise the execution will be error.
Then run BUILD.bat and wait for the end.
The program compiles other platforms to compile the libraries and compile files required by go.
When you are finished, follow the cmd command line in turn:
Set Goos=linux
Set GOPACH=AMD64
Go build-o-x APPNAME main.go
The compiled file will appear in the corresponding directory in Main.go.