首页 > go > GO 编译各平台下应用

GO 编译各平台下应用

1、Mac下编译Linux, Windows

# Linux
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build filename.go

# Windows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build filename.go

2、Linux下编译Mac, Windows

# Mac
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build filename.go

# Windows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build filename.go

3、Windows下编译Mac, Linux

# Mac
SET CGO_ENABLED=0
SET GOOS=darwin
SET GOARCH=amd64
go build filename.go

# Linux
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64

 

GOOS:目标平台的操作系统(darwin、freebsd、linux、windows)
GOARCH:目标平台的操作系统位数 386 32位系统,amd64 64位系统(386、amd64、arm)