我的环境
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
我在我的 mac 上编译并成功执行了二进制文件,然后将其复制到上面显示的 go env 的 ubuntu 机器上。当我调用 myprog 二进制文件时,我得到了
bash: /usr/local/go/bin/myprog: cannot execute binary file: Exec format error
最佳答案
从 go 1.5 开始,交叉编译变得非常简单。有点像
env GOOS=linux GOARCH=amd64 go build -v github.com/constabulary/gb/cmd/gb
引用http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5 .
关于golang 无法执行二进制文件 : Exec format error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36198418/