Golang-全平台交叉编译

Golang的交叉编译要保证golang版本在1.5以上,我的环境是go1.11.5 darwin/amd64

交叉编译

1
2
3
4
5
6
7
8
9
10
11
# mac上编译linux和windows二进制
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

# linux上编译mac和windows二进制
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

# windows上编译mac和linux二进制
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
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×