是否可以使用Go编译器为其他操作系统分发可执行文件? [英] Is it possible to use the Go compiler to distribute a executable file for other os?

查看:164
本文介绍了是否可以使用Go编译器为其他操作系统分发可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Mac OS X,现在我需要构建一个.exe文件,以便Go程序可以在Windows上运行。
所以这里是一个问题,如何在MacOS amd64下为Win X86构建一个可执行文件?或者它是不可能的?

I am currently working on Mac OS X, now I need to build a .exe file so that the Go program can run on windows. So here is the question, how to build a executable file for Win X86 under MacOS amd64 ? or Is it impossible to do so ?

推荐答案

如果你不使用CGo而是纯粹的Go,那么它是完全可行的, 。

If you don't use CGo but pure Go, then it's perfectly doable and standard.

首先,您必须在开发计算机上为目标制作Go环境。假设你的Go安装在〜/ var / go 中,这可能是这样的:

First you have to make the Go environment on your development computer for the targets. Supposing your Go installation is in ~/var/go, this may be this :

cd ~/var/go/src
CGO_ENABLED=0 GOOS=windows GOARCH=386 ./make.bash



然后你用良好的GOOS和GOARCH进行编译:

Then you compile with the good GOOS and GOARCH :

GOOS=windows GOARCH=386 go build -o hello.exe hello.go

以下是关于在Linux上构建Windows EXE的go-wiki页面

这篇关于是否可以使用Go编译器为其他操作系统分发可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆