Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: provide better error message than "relocation target main.main not defined" when no func main provided #24809

Closed
josharian opened this issue Apr 11, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@josharian
Copy link
Contributor

commented Apr 11, 2018

There has been a recent spate of issues and noise on issues, in which people report that the linker is complaining: relocation target main.main not defined. This happens when the main package has no func main.

Since that is a common error mode, particularly for new Go programmers, we should provide a more useful error message.

I thought there was an existing issue open for this, but I can't find it.

@josharian josharian added the NeedsFix label Apr 11, 2018

@josharian josharian added this to the Go1.11 milestone Apr 11, 2018

@ALTree

This comment has been minimized.

Copy link
Member

commented Apr 11, 2018

I thought there was an existing issue open for this, but I can't find it.

That's #10978

@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Apr 11, 2018

Thanks. I think those are close enough that I'll close this as a dup.

@josharian josharian closed this Apr 11, 2018

@gopherbot

This comment has been minimized.

Copy link

commented May 21, 2018

Change https://golang.org/cl/113955 mentions this issue: cmd/link: fix duplicated "undefined reloc" errors

gopherbot pushed a commit that referenced this issue Jun 5, 2018

cmd/link: fix duplicated "undefined reloc" errors
For given program with 2 undefined relocations (main and undefined):

	package main
	func undefined()
	func defined() int {
		undefined()
		undefined()
		return 0
	}
	var x = defined()

"go tool link" produces these errors:

	main.defined: relocation target main.undefined not defined
	main.defined: relocation target main.undefined not defined
	runtime.main_main·f: relocation target main.main not defined
	main.defined: undefined: "main.undefined"
	main.defined: undefined: "main.undefined"
	runtime.main_main·f: undefined: "main.main"

After this CL is applied:

	main.defined: relocation target main.undefined not defined
	runtime.main_main·f: function main is undeclared in the main package

Fixes #10978
Improved error message for main proposed in #24809.

Change-Id: I4ba8547b1e143bbebeb4d6e29ea05d932124f037
Reviewed-on: https://go-review.googlesource.com/113955
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>

@golang golang locked and limited conversation to collaborators May 21, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.