我的环境
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"
Run Code Online (Sandbox Code Playgroud)
我在我的mac上编译并成功执行了二进制文件,然后将其复制到上面显示go env的ubuntu机器上.当我调用myprog二进制文件时,我得到了
bash: /usr/local/go/bin/myprog: cannot execute binary file: Exec format error
Run Code Online (Sandbox Code Playgroud)
Wea*_*ter 35
从1.5开始,交叉编译器变得非常简单.就像是
env GOOS=linux GOARCH=amd64 go build -v github.com/constabulary/gb/cmd/gb
Run Code Online (Sandbox Code Playgroud)
请参阅http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5.
我有同样的问题。我安装了 64 位版本的 go 而不是 32 位版本。安装 32 位版本后,它工作正常。