go语言的交叉编译

GGox 是一个简单的,不花俏的Go平台交叉编译工具,它的用处就和标准的 go build 同样。Gox 会并行地为多种平台编译。Gox 同时也提供了一套交叉编译工具链。 linux

GGox 项目地址:https://github.com/mitchellh/gox git

安装

为了安装 Gox,请使用 go get。咱们已经为版本打上了标签,因此能够随便切换标签进行编译: github

$ go get github.com/mitchellh/gox
...
$ gox -h
... windows


用法

在你使用 Gox 以前,你必须先有一套交叉编译工具链。Gox 能够自动帮你完成这个。你须要作的只是运行(每次更新 Go 都要这样作这步): 工具

$ gox -build-toolchain
... ui

当你完成这个,你能够已经准备好进行交叉编译了。
若是你知道怎么去使用 go build, 那么你也知道怎么去使用 Gox 了。例如,编译当前的项目,无需提供参数,只须要调用gox。Gox 就会根据 CPU 的数量并行地为各个平台编译: spa


$ gox
Number of parallel builds: 4 get

--> darwin/386: github.com/mitchellh/gox
--> darwin/amd64: github.com/mitchellh/gox
--> linux/386: github.com/mitchellh/gox
--> linux/amd64: github.com/mitchellh/gox
--> linux/arm: github.com/mitchellh/gox
--> freebsd/386: github.com/mitchellh/gox
--> freebsd/amd64: github.com/mitchellh/gox
--> openbsd/386: github.com/mitchellh/gox
--> openbsd/amd64: github.com/mitchellh/gox
--> windows/386: github.com/mitchellh/gox
--> windows/amd64: github.com/mitchellh/gox
--> freebsd/arm: github.com/mitchellh/gox
--> netbsd/386: github.com/mitchellh/gox
--> netbsd/amd64: github.com/mitchellh/gox
--> netbsd/arm: github.com/mitchellh/gox
--> plan9/386: github.com/mitchellh/gox it

或者,你只想编译某个项目和子项目: 编译

$ gox ./...
...

或者,你想仅仅为 linux 编译:

$ gox -os="linux"
...

或者,你仅仅只想为 64 位的 linux 编译:

$ gox -osarch="linux/amd64"
...

还有更多的选项,能够经过 gox -h 查看帮助。

相关文章
相关标签/搜索