网上找了一下,没有找到相关文档,但是文章是有的
Building Go Applications for Different Operating Systems and Architectures
How To Build Go Executables for Multiple Platforms on Ubuntu 16.04
Golang 支持在一个平台下生成另一个平台可执行程序的交叉编译功能。
Mac下编译Linux, Windows平台的64位可执行程序:
1 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build test.go |
Linux下编译Mac, Windows平台的64位可执行程序:
1 | CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build test.go |
Windows下编译Mac, Linux平台的64位可执行程序,注意一下用CMD:
1 | CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build test.go |
GOOS:目标可执行程序运行操作系统,支持 darwin,freebsd,linux,windows GOARCH:目标可执行程序操作系统构架,包括 386,amd64,arm