go语言window|mac|linux下交叉编译其他平台的软件包

go语言window|mac|linux下交叉编译其他平台的软件包

注意:go1.17 发现直接使用set 是不起作用的, 必须要使用go env -w 来设置

一、设置编译环境,需要发布哪个平台

Window下

1、 设置Linux编译环境
SET CGO_ENABLED=0
set GOARCH=amd64
set GOOS=linux
2、设置Mac编译环境
go env -w  CGO_ENABLED=0
go env -w  GOOS=darwin
go env -w  GOARCH=amd64

Linux下

# Mac
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build filename.go
 
# Windows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build filename.go

Mac下

# Linux
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build filename.go
 
# Windows
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build filename.go
如: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o helloworld-windows helloworld.go

二、开始编译

go build -o ./"要生成的文件 .\源代码

设置环境后,在自己的命令行窗口运行 go env命令,查看你刚刚修改的参数是否修改了,修改后,即可进行编译;

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_2848.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?