輕輕鬆鬆,Go 真方便。
1 2 3 | GOOS=linux GOARCH=mipsle go build Web.go #Web.go 取代為你自己要編譯的code #Linkit 7688 為 mipsle |
好,問題又來了,要編譯有cgo的go檔案時,需要將相對應的gcc安裝好並且設定編譯成static
因此首先,需要在自己的Ubuntu環境內先安裝相對應的gcc工具
1 2 3 | #7688 為mipsle版本 sudo apt-get install gcc-5-mipsel-linux-gnu g++-5-mipsel-linux-gnu libc6-dev-mipsel-cross #參考至 xgo docker:https://github.com/karalabe/xgo/blob/master/docker/base/Dockerfile |
安裝好後,即可下指令compile你含有cgo的程式了,
這邊我是compile go sqlite3的example
1 2 3 4 5 | CGO_ENABLED=1 GOOS=linux GOARCH=mipsle CC=mipsel-linux-gnu-gcc CXX=mipsel-linux-gnu-g++ \ go build -v -ldflags "-linkmode external -extldflags -static" simple.go #編譯好後,可以用file檢查檔案是否為static #simple: ELF 32-bit LSB executable, MIPS, MIPS32 version 1, statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=19e55e478df9906f05ba1963671d58b90acbab13, not stripped #顯示此訊息代表成功 |