一般我们在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)

相关文章:

  • 2022-01-21
  • 2021-10-04
  • 2021-07-17
  • 2022-02-07
  • 2022-01-31
  • 2021-09-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-15
  • 2021-04-02
  • 2021-06-06
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
相关资源
相似解决方案