2.7 Go cross compiler

Golang support cross-compiler, generating another platform executable program on a single platform, recently used a little, very easy to use, memo here.

Mac compile under Linux and Windows  64-Wei executable program

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

Mac and Linux compiler under Windows 64-bit executable program

CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

Compiled under Windows and Linux 64-bit Mac executables

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

GOOS: target platform operating system (darwin, freebsd, linux, windows) GOARCH: architecture target platform (386, amd64, arm) cross-compiler does not support CGO

Guess you like

Origin www.cnblogs.com/open-yang/p/11256731.html