Golang交叉编译

GOOS:目标平台的操作系统(darwin、freebsd、linux、windows)
GOARCH:目标平台的体系架构(386、amd64、arm、arm64)

MacOS

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

Linux

#darwin-amd64
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
#linux-arm64
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build main.go
#wondows-amd64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

Windows

#darwin-amd64
SET CGO_ENABLED=0
SET GOOS=darwin
SET GOARCH=amd64
go build main.go
#linux-amd64
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build main.go
#linux-arm64
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=arm64
go build main.go

你可能感兴趣的:(Golang交叉编译)