1. Home
  2. Docs
  3. golang
  4. 发布

发布

构建打包go run main.go

如何在windows下构建linux程序?

设置环境变量再重新构建

# 编译linux程序
set GOARCH=amd64
set GOOS=linux

go run main.go

# 编译mac程序
SET CGO_ENABLED=0
SET GOOS=darwin
SET GOARCH=amd64
go build main.go

Mac 下编译 Linux 和 Windows 64位可执行程序

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 64位可执行程序

CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

相关资料

Mac、Linux、Windows交叉编译

Was this article helpful to you? Yes No

How can we help?