Gox : 簡單實在的Go平台交叉編譯工具

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

Gox 是一個簡單的,不花俏的Go平台交叉編譯工具,它的用處就和標準的 go build 一樣。Gox 會並行地為多種平台編譯。Gox 同時也提供了一套交叉編譯工具鏈。

Gox 項目地址:https://github.com/mitchellh/gox

安裝

為了安裝 Gox,請使用 go get。我們已經為版本打上了標籤,所以可以隨便切換標籤進行編譯:

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

用法

在你使用 Gox 之前,你必須先有一套交叉編譯工具鏈。Gox 可以自動幫你完成這個。你需要做的只是運行(每次更新 Go 都要這樣做這步):

$ gox -build-toolchain
...

當你完成這個,你可以已經準備好進行交叉編譯了。
如果你知道怎麼去使用 go build, 那麼你也知道怎麼去使用 Gox 了。例如,編譯當前的項目,無需提供參數,只需要調用 gox。Gox 就會根據 CPU 的數量並行地為各個平台編譯:

$ gox
Number of parallel builds: 4

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

或者,你只想編譯某個項目和子項目:

$ gox ./...
...

或者,你想僅僅為 linux 編譯:

$ gox -os="linux"
...

或者,你僅僅只想為 64 位元的 linux 編譯:

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

還有更多的選項,可以通過 gox -h 查看協助。

和其他交叉編譯工具的比較

非常感謝這些工具為我們提供了更多的選擇,它們為 go 平台的交叉編譯工具提供做了很多方面的貢獻.

  • Dave Cheney的交叉編譯器: Gox 可以為多種平台編譯,所以也能容易地運行在各種 Go 支援的平台上。但Dave的那個需要一個 shell 來運行。Gox 支援並行地編譯,但 Dave 的只是按順序地編譯。Gox 也能非常方便地使用的內建的 arch 系統的內建過濾工具。
  • goxc:它是一個功能豐富的工具,能編譯系統項目,上傳二進位檔案,產生下載頁面等;相較之下,Gox 在交叉編譯二元檔案方面稍稍弱些。但 Gox 能並行地編譯項目,而 goxc 不能。Gox 也沒有強制指定編譯二元檔案時輸出結果的格式。

翻譯整理:SegmentFault

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.