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

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

问题描述

我试图在OSX上交叉编译一个go应​​用程序来构建windows和linux的二进制文件。我读了一切我可以在网上找到的东西。我发现的最近的例子已经发布(除了许多关于go-nuts邮件列表的未完成的讨论):



http://solovyov.net/en/2012/03/09/cross-compiling-go/



但它不适用于我的安装。我去了1.0.2。由于1.0.2是最近的,它看起来对我来说,所有上面的例子不适用于这个版本。



尝试做 ./ make。 bash --no-clean 将ENV的vars设置为386 / windows,它会构建go,但是它为我的安装,这是 darwin / amd64 并完全忽略ENV中设置的假设构建不同编译器的设置。



任何建议如何做(如果可以做到的话)?

解决方案

使用Go 1.5,他们似乎已经改进了交叉编译过程,意味着它是现在内置的。不需要 ./ make.bash -ing或 brew 。该过程在此处中描述,但对于TLDR-ers(像我一样):你只需设置 GOOS GOARCH 环境变量并运行go build。 p>

如果你在一个* nix系统上,对于那些甚至是lazier的copy-pasters(像我),你可以这样做:

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

你甚至学会了 env 技巧,它只允许为该命令设置环境变量,


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-compiling-go/

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.

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)?

解决方案

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.

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

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

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

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