Jim Syyap
Jim Syyap

Reputation: 1673

exec format error

I recently installed lubuntu 11.04 on my pc. Following this guide on installing go from source, installing golang on my pc went well. To test my installation, I ran hello.go and got this error:

fork/exec /tmp/go-build748212890/command-line-arguments/_obj/a.out: exec format error

I looked it up on google, and one of the more relevant results that I found said to remove the package, then reinstall again. That did not help.

Can you tell me what is causing this error, and how I can fix this?

Thanks, and have a nice day!

Upvotes: 9

Views: 26256

Answers (4)

Dean Jain
Dean Jain

Reputation: 2208

open your shell profile ex: .zshrc file and edit it:

$vi .zshrc

remove below two lines

GOARCH="amd64/whatever"
GOOS="linux/whatever"

Save the file and exit editor

apply changes to profile using source command or restart a new shell:

source .zshrc

rerun the go code and it resolved for me.

Upvotes: 0

Kassab
Kassab

Reputation: 143

This did the trick for me.

export GOARCH="amd64"

https://github.com/golang/go/issues/53116

Upvotes: 0

Nsubuga Kasozi
Nsubuga Kasozi

Reputation: 21

got this error on windows from Goland. The issue was that the test cases were nested and had pretty lengthy names which meant that the resultant binary had a file path with a super long name. Windows has a max file path limit of 260 characters and the total length of the file path to the binary exceeded that limit hence the error. e.g

t.Run("Authentication Tests", func(t *testing.T) {
    t.Run("Given my conditions, when the function xyz is called, we expect this super 
           important result", func(t *testing.T) {

         })
})

The solution was to use fewer words in the test case names

Upvotes: 0

rfay
rfay

Reputation: 12805

I had this problem - it was very simple: I had set $GOOS to something other than the OS I was testing on. You can't do cross-platform testing. So for "go test", don't set $GOOS. I'm pretty sure the "Exec format error" you got was a result of go test trying to execute something on the wrong architecture/OS.

Upvotes: 21

Related Questions