- Go ENV Check the environment variables are correct
- Enter the shell environment (Windows is a CMD environment) and switch to the project source directory (the directory containing the main package)
- Set the environment variables, close the CGO (cross-compilation does not support so to close), set the environment variables to compile the target platform, and then execute the Go Build command, the method is as follows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build
The bash shell environment can be used as above, and if it is a Windows CMD environment, set with the SET command
cgo_enabled Close Cgo,goos Set Target operating system, Goarch set Target schema
Can be combined with the following
$GOOS $GOARCHandroid armdarwin 386darwin amd64darwin armdarwin arm64dragonfly amd64freebsd 386freebsd amd64freebsd armlinux 386linux amd64linux armlinux arm64linux ppc64linux ppc64lelinux mipslinux mipslelinux mips64linux mips64lenetbsd 386netbsd amd64netbsd armopenbsd 386openbsd amd64openbsd armplan9 386plan9 amd64solaris amd64windows 386windows amd64
Set the environment variable and then execute the Go Build command to compile the executable file on the target platform.