The following column will introduce you to Golang cross-compilation under various platforms from the golang tutorial column. I hope it will be helpful to friends in need!
#Golang supports cross-compilation, which can generate an executable program for another platform on one platform. I have used it recently and it is very easy to use. Here is a note.
Parameter description
Cross compilation does not support CGO so disable it
Compile Linux and Windows 64-bit executable programs under Mac
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
Compile Mac and Windows 64-bit executable programs under Linux
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
Compile Mac and Linux 64-bit executable programs under Windows
SET CGO_ENABLED=0 SET GOOS=darwin SET GOARCH=amd64 go build main.go SET CGO_ENABLED=0 SET GOOS=linux SET GOARCH=amd64 go build main.go
The above command compiles a 64-bit executable program. Of course you should also use 386 to compile a 32-bit executable program
More golang related technologies For articles, please visit the go language column!
The above is the detailed content of Golang is cross-compiled under various platforms. For more information, please follow other related articles on the PHP Chinese website!