[Go] Windows/Linux/Mac交叉编译成指定系统的二进制可执行文件

一般我们在windows获取mac开发代码 , 编译的时候如果要编译成指定系统的二进制文件 , 这时就需要使用交叉编译

1. 在Windows下编译Mac, Linux
编译成 Mac
SET CGO_ENABLED=0
SET GOOS=darwin
SET GOARCH=amd64
go build xxxx.go

编译成 Linux
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build xxxx.go

2.Mac下编译Linux, Windows

 编译成 Linux
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build xxxx.go
 编译成 Windows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build xxxx.go

3.Linux下编译Mac, Windows
编译成 Mac
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build xxxx.go
编译成 Windows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build xxxx.go

 

设置了这个以后速度会慢 , 原因是标准库的包需要重新构建 

CGO_ENABLED=0 

 

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

上一篇:如何将本地已经存在的项目上传到gitlab上


下一篇:Ubuntu中“fatal: unable to access ‘https://github.com/xxxx/xxxx.git‘: Failed to connect to 127……”解决方案