Hello, I’m new to Go and I’m having trouble even getting a hello world example to run. When I try to run it with “go run hello.go” I get the following error:
$ go run hello.go
# command-line-arguments
panic: runtime error: index out of range [2147479547] with length 7
goroutine 1 [running]:
cmd/link/internal/loader.(*Loader).resolve(0x1e36?, 0xc000115280?, {0x4300?, 0xc0?})
/usr/lib/golang/src/cmd/link/internal/loader/loader.go:662 +0x1ae
cmd/link/internal/loader.Reloc.Sym({0x7f047b076948?, 0xc000115280?, 0xc000004300?})
/usr/lib/golang/src/cmd/link/internal/loader/loader.go:60 +0x35
cmd/link/internal/ld.(*deadcodePass).flood(0xc000120a08)
/usr/lib/golang/src/cmd/link/internal/ld/deadcode.go:204 +0x878
cmd/link/internal/ld.deadcode(0xc000150000)
/usr/lib/golang/src/cmd/link/internal/ld/deadcode.go:336 +0x89
cmd/link/internal/ld.Main(_, {0x20, 0x20, 0x1, 0x7, 0x10, 0x0, {0x0, 0x0}, {0x697b59, ...}, ...})
/usr/lib/golang/src/cmd/link/internal/ld/main.go:271 +0xef2
main.main()
/usr/lib/golang/src/cmd/link/main.go:72 +0xedb
My code is just the following:
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
I tried googling this but nothing seems to help fix it. I’m on Fedora 38 using the distro’s packages and the file lives under ~/go/src/hello/hello.go which is where I’m trying to run it from.
I decided to try your advice by removing the Go package and installing from the website as per the instructions and it seems to function like it should now. It’s perplexing that the Fedora installed environment was broken like this though.
I used to use package managers like apt to keep golang up to date but the install is so easy I have switched over to just manually installing it using the instructions on go.dev and that seems to work better than package managers for whatever reason. And I don’t have to lag a few versions behind while waiting for package maintainers. Glad you were able to get it working.