Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

golang cannot execute binary file: Exec format error

Tags:

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 
like image 305
mg03 Avatar asked Mar 24 '16 10:03

mg03


1 Answers

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.

like image 62
WeakPointer Avatar answered Sep 20 '22 16:09

WeakPointer