编译环境: Mac+Docker
因为sqlite使用了cGo,所以跨平台编译的时候,需要将相关依赖包也处理一下。
这儿推荐使用xgo打包工具,结合Docker。本教程适用于Mac 。
当然,另外一个解决方法是,安装不同的虚拟机。分平台打包。
安装docker、配置Go环境省略
拉取镜像
docker pull karalabe/xgo-latest
安装打包工具(它的作用就是调用docker镜像中的命令)
go get github.com/karalabe/xgo
平台参数
--targets=linux/arm : builds only the ARMv5 Linux binaries (arm-6/arm-7 allowed)
--targets=windows/*,darwin/* : builds all Windows and OSX binaries
--targets=*/arm : builds ARM binaries for all platforms
--targets=*/* : builds all suppoted targets (default)
参数可选如下
Platforms: android, darwin, ios, linux, windows
Achitectures: 386, amd64, arm-5, arm-6, arm-7, arm64, mips, mipsle, mips64, mips64le
打包方式,借助gmp这个开源的组件
如下
cd golang/src/xxd
xgo --deps=https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2 --targets=linux/386 .
xgo --deps=https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2 --targets=linux/amd64 .
xgo --deps=https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2 --targets=windows/386 .
xgo --deps=https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2 --targets=windows/amd64 .
xgo --deps=https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2 --targets=darwin/amd64 .
开源项目地址:https://github.com/karalabe/xgo
GMP组件官网:https://gmplib.org