交叉编译在OSX上? [英] Cross compile Go on 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 isdarwin/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 orbrew
-ing required. The process is described here but for the TLDR-ers (like me) out there: you just set theGOOS
and theGOARCH
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屋!