exec format error
Asked Answered
go
K

4

9

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!

Krysta answered 14/12, 2012 at 0:32 Comment(6)
How did you ran hello.go ? Using go run ?Morganite
Please add the output of go env and env | grep GO and maybe a uname -aRheotaxis
I ran hello go with "go run hello.go"Krysta
After 24-hours, I couldn't find a workaround. I decided to replace lubuntu with archbang. Golang works now.Krysta
Why 11.04 rather than 12.04 LTS or 12.10?Tranship
#14944417Cuddle
N
21

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.

Noellenoellyn answered 23/5, 2017 at 22:53 Comment(1)
For me, removing GOARCH did the trick, inspired by your answer of courseHoratius
R
0

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

Roundhead answered 13/5, 2021 at 15:23 Comment(1)
FWIW, in Win10 it's possible to remove the 260 chars path limit. See howtogeek.com/266621/…Valonia
L
0

This did the trick for me.

export GOARCH="amd64"

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

Lurdan answered 23/8, 2023 at 6:43 Comment(0)
P
0

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.

Presbyterial answered 12/7 at 23:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.