Cross Compiling 環境設定 (MAC)
主要參考來源:
https://dh1tw.de/2019/12/cross-compiling-golang-cgo-projects/
目前自己的作法是,採用ubuntu的docker
然後安裝該裝的cc工具:
Operating System | Architecture | Needed package(s) |
---|---|---|
Linux | armhf | gcc-arm-linux-gnueabihf |
libc6-dev-armhf-cross | ||
Linux | arm64 | gcc-aarch64-linux-gnu |
libc6-dev-arm64-cross | ||
Linux | i386 | gcc-multilib |
libc6-dev-i386 | ||
linux-libc-dev:i386 | ||
Windows | amd64 | gcc-mingw-w64-x86-64 |
Windows | i386 | gcc-mingw-w64-i686 |
然後就可以輕鬆build了...
附註:
對於mips平台(例如MTK7688)
就尋找gcc-mips / libc6-dev-mips...
具體看你的mips平台支援哪種 (Linux下用uname -a看一下)
更新:ARM系列與X86-64系列的,Mac下直接安裝套件就好
https://github.com/osx-cross/homebrew-arm
https://github.com/messense/homebrew-macos-cross-toolchains
brew tap messense/macos-cross-toolchains
# install x86_64-unknown-linux-gnu toolchain
brew install x86_64-unknown-linux-gnu
# install aarch64-unknown-linux-gnu toolchain
brew install aarch64-unknown-linux-gnu
然後在/usr/local/bin 查一下要用的cc
GOOS=linux GOARCH=arm64 GOARM=7 CGO_ENABLED=1 CC=aarch64-unknown-linux-gnu-cc go build
留言