Golang supports the ability to generate cross-compilation of another platform executable program under one platform.
Linux under Mac, 64-bit executable program for Windows platform:
1 cgo_enabled=0 goos=linux goarch=amd64 go build [Application | gofile.go]2 cgo_ enabled=0 goos=windows goarch=amd64 go build [Application | gofile.go]
Linux under Compile Mac, Windows platform 64-bit executable:
1 cgo_enabled=0 goos=darwin goarch=amd64 go build [Application | gofile.go]2 cgo_ enabled=0 goos=windows goarch=amd64 go build [Application | gofile.go]
Windows compiles 64-bit executables for Mac, Linux platforms:
1 Set cgo_enabled=02 set goos=Darwin3 set goarch=amd644 go build [Application | gofile.go]56 set cgo_enabled=07 Set GOOS =Linux8 SET goarch=amd649 Go build [Application | gofile.go]
GOOS: The target executable program runs the operating system and supports Darwin,freebsd,linux,windows
Goarch: Target executable program operating system architecture, including 386,amd64,arm
Golang version 1.5 The cross-compilation environment also needs to be configured during the first cross-compilation:
1 cgo_enabled=0 goos=linux goarch=amd64./make. Bash2 cgo_enabled=0 goos=windows goarch=amd64./make. Bash
Make.bash files are only used when the Golang source code is compiled and installed.
Golang cross-compiling on Mac, Linux, Windows