在 OSX 上交叉编译? [英] Cross compile Go on OSX?

查看:29
本文介绍了在 OSX 上交叉编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 OSX 上交叉编译一个 go 应用程序来为 windows 和 linux 构建二进制文件.我已经阅读了我在网上能找到的所有内容.我发现的最接近的例子已经发布(除了关于 go-nuts 邮件列表的许多未完成的讨论):

I am trying to cross-compile a go app on OSX to build binaries for windows and linux. I have read everything what I could find on the net. Closest example that I have found has been published on (apart from many unfinished discussions on go-nuts mailing list):

http://solovyov.net/en/2012/03/09/cross-编译去/

但它在我的安装中不起作用.我已经去了 1.0.2.由于 1.0.2 是最新的,在我看来,上述所有示例都不适用于此版本.

yet it does not work on my installation. I have go 1.0.2. As 1.0.2 is quite recent it looks to me that all above examples do not apply to this version.

尝试在 ENV 变量设置为 386/windows 的情况下执行 ./make.bash --no-clean,它确实构建了,但是它为我的安装构建了darwin/amd64 并完全忽略在 ENV 中设置的假设构建不同编译器的内容.

Tried to do ./make.bash --no-clean with ENV vars set to 386/windows, it does build go, however it builds go for my installation which is darwin/amd64 and completely ignores what is set in ENV that suppose to build different compiler.

任何建议如何完成(如果可以完成)?

Any advises how it can be done (if it can be done at all)?

推荐答案

在 Go 1.5 中,他们似乎改进了交叉编译过程,这意味着它现在已内置.不需要 ./make.bash-ing 或 brew-ing.此处描述了该过程,但对于 TLDR 用户(像我一样)在那里:您只需设置 GOOSGOARCH 环境变量并运行 go build.

With Go 1.5 they seem to have improved the cross compilation process, meaning it is built in now. No ./make.bash-ing or brew-ing required. The process is described here but for the TLDR-ers (like me) out there: you just set the GOOS and the GOARCH environment variables and run the go build.

对于那些更懒惰的复制粘贴者(如我),如果您使用的是 *nix 系统,请执行以下操作:

For the even lazier copy-pasters (like me) out there, do something like this if you're on a *nix system:

env GOOS=linux GOARCH=arm go build -v github.com/path/to/your/app

你甚至学会了 env 技巧,它让你只为那个命令设置环境变量,完全免费.

You even learned the env trick, which let you set environment variables for that command only, completely free of charge.

这篇关于在 OSX 上交叉编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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