Go语言的交叉编译

因为Go 1.5对跨平台编译有了一些改进,包括统一了编译器、连接器等。 编译时候只须要指定两个参数:GOOS和GOARCH便可。linux

示例:windows

# 编译到 linux 64bit
$ GOOS=linux GOARCH=amd64 go build
# 或者能够使用 -o 选项指定生成二进制文件名字
$ GOOS=linux GOARCH=amd64 go build -o app.linux

# 编译到 linux 32bit
$ GOOS=linux GOARCH=386 go build

# 编译到 windows 64bit
$ GOOS=windows GOARCH=amd64 go build

# 编译到 windows 32bit
$ GOOS=windows GOARCH=386 go build

# 编译到 Mac OS X 64bit
$ GOOS=darwin GOARCH=amd64 go build
  • GOOS: 系统平台(还支持 windows、darwin)
  • GOARCH: CPU 架构(还支持 amd6四、386 等)
相关文章
相关标签/搜索