go: relocation target main.main not defined

Please answer these questions before submitting your issue. Thanks!

What did you do?

I was trying to out put some String “This is less” below is the program

package main

func main() {
	i := 3
	if i < 3 {
		println("This is less")
	}
}

What did you expect to see?

The output should be “This is less”

What did you see instead?

Each time it tells me that my main has not been defined. Yet I have already defined it. Here is a complete error message:

# command-line-arguments
runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"
dennis@dennis-HP-Notebook:~/Desktop/Go Proj

System details

go version go1.10.1 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dennis/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dennis/go"
GORACE=""
GOROOT="/snap/go/1688"
GOTMPDIR=""
GOTOOLDIR="/snap/go/1688/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build360112992=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.10.1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.10.1
uname -sr: Linux 4.13.0-37-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.4 LTS
Release:	16.04
Codename:	xenial
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.23-0ubuntu10) stable release version 2.23, by Roland McGrath et al.
gdb --version: GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 17 (8 by maintainers)

Most upvoted comments

@jaytaylor There is no main function in that file, so the error is normal and expected.

Whether this is the same problem as @dennismuturia I do not know.

I hit this error when I accidentally defined func Main() instead of func main().