当前位置: 动力学知识库 > 问答 > 编程问答 >

go - golang cannot execute binary file: Exec format error

问题描述:

my go env

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"

I compiled and successfully executed the binary on my mac and then copied it to the ubuntu machine whose go env is show above. When I call myprog binary, I get

bash: /usr/local/go/bin/myprog: cannot execute binary file: Exec format error

网友答案:

Since go 1.5, cross compiler has gotten pretty easy. Something like

env GOOS=linux GOARCH=amd64 go build -v github.com/constabulary/gb/cmd/gb

Refer to http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5.

网友答案:

I had the same problem. I installed 64-bit version of go instead of 32-bit version. After installation of 32-bit version it works fine.

分享给朋友:
您可能感兴趣的文章:
随机阅读: