问题描述
我目前正在使用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
以下是。
这篇关于是否可以使用Go编译器为其他操作系统分发可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!