在mac系统下交叉编译出错
用CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build
报错,转而使用xgo
。 应该是cgo的交叉编译还不完善。
$ go get github.com/karalabe/xgo #生成xgo可执行程序,配置到path环境变量下
$ vim /etc/profile
export PATH=$GOPATH/bin:$PATH
$ cd $GOPATH/src/wallet_app
$ xgo -out wallet_app --targets=linux/amd64 ./ #xgo需要docker,启动docker后,执行该命令时会自动拉取镜像
生成一个wallet_app-linux-amd64
文件,放到linux下运行即可。
如果用了vendor,编译时可能报错:fatal error: 'libsecp256k1/include/secp256k1.h' file not found
解决方法是手动把这些文件移到vendor目录下:
$ cp -r \
"${GOPATH}/src/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1" \
"vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/"