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

plugin: runtime.main_main·f: undefined: "main.main"(buildmode=plugin) #20312

Closed
kenkao opened this issue May 10, 2017 · 18 comments
Closed

plugin: runtime.main_main·f: undefined: "main.main"(buildmode=plugin) #20312

kenkao opened this issue May 10, 2017 · 18 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@kenkao
Copy link

kenkao commented May 10, 2017

I want to build a plugin for my program, and the main content is ...

package main

import (
        "mylib"
        ......
)

The package "mylib" is a package of my defined, when I import it and then build it, the error will occur ...

command-line-arguments
runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"

why? Thanks a lot!

@bradfitz bradfitz changed the title runtime.main_main·f: undefined: "main.main"(buildmode=plugin) plugin: runtime.main_main·f: undefined: "main.main"(buildmode=plugin) May 10, 2017
@bradfitz bradfitz added this to the Unplanned milestone May 10, 2017
@bradfitz
Copy link
Contributor

@kenkao, please provide a complete repro (code & commands you ran), and include the output of go bug.

@crawshaw, maybe you recognize this as a dup of something else?

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 10, 2017
@kenkao
Copy link
Author

kenkao commented May 11, 2017

@bradfitz
Thanks for your replying!
I have found the answer, because I import the package "plugin" in "mylib" . (Σ( ° △ °|||)︴)
I want to use the "go build" to build the main app, and use "go build plugin" to build the "main.so", then I can let the main to load the "main.so" for itself's hotloading
Can't I ?

@bradfitz
Copy link
Contributor

No clue.

@kenkao
Copy link
Author

kenkao commented May 11, 2017

@bradfitz
The source code is here:
https://github.com/kenkao/plugintest

go version go1.8 linux/amd64

cd main/
go build -ldflags "-pluginpath=plugin/hot-$(date +%s)" -buildmode=plugin -o gplugin.so gplugin.go

@jimmiebtlr
Copy link

You have 2 main functions defined in your main package. I was getting a similar error when I had none defined in a package main.

@jordy25519
Copy link

In my case I had not defined a function called main i.e. func main(){}

@bsed
Copy link

bsed commented Jul 10, 2017

[root@localhost main]#  go build -ldflags "-pluginpath=plugin/hot-$(date +%s)" -buildmode=plugin -o gplugin.so gplugin.go

command-line-arguments

runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"
[root@localhost main]#

Kubuxu added a commit to ipfs/kubo that referenced this issue Jul 26, 2017
golang/go#20312

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
nelsam added a commit to nelsam/vidar that referenced this issue Jul 30, 2017
This is related to golang/go#20312, which causes plugin main packages to fail tests.
We don't have very well-tested code in general, so I'm not that worried about skipping
these packages.
@kenkao
Copy link
Author

kenkao commented Aug 9, 2017

@jimmiebtlr
the 'main' func in gplugin.go is an redundant code block for my debuging, i have deleted it. but when you want to build the gplugin.go to a plugin.so, the same error will occur..
i guess that you cannot import any package imported the 'plugin' package (╮( ̄▽ ̄")╭), when you want to build it to a plugin.so (the 'gplugin' import the 'mylib', and the 'mylib' import the 'plugin')
i think it may be beneficial to the security of golang..

@kenkao
Copy link
Author

kenkao commented Aug 9, 2017

my hot-update based on plugin for go has succeeded! ^ ^

@crawshaw
Copy link
Member

crawshaw commented Sep 2, 2017

It sounds like this was resolved when you added func main() {} to your plugin. For now, the main function is required and documented, so I'm going to close this.

(If I misunderstood this issue, please comment and I'll reopen it.)

@crawshaw crawshaw closed this as completed Sep 2, 2017
@nzlov
Copy link

nzlov commented Sep 30, 2017

@crawshaw
When import plugin in plugin:

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

demo

@crawshaw
Copy link
Member

You need to add func main() {} to your plugin.

@nzlov
Copy link

nzlov commented Sep 30, 2017

@crawshaw
Sorry, I have added func main () {} to plugin/plugin.go and models/models.go, but still hold the wrong.

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

demo

@KubisGroup
Copy link

Hello I've a same this problem.
but... I've 3 folders for 3 applications (app-test, app-update, app-deploy)
1st app-test it will be ok and running as server
but when I create second app-update for check heartbeat of first app that i cant use "package main" but when I need run it that I can't
What/How I can fix it... Thank you

@ianlancetaylor
Copy link
Contributor

@KubisGroup Please ask questions on a forum; see https://golang.org/wiki/Questions. You will get a better and faster response. When asking your question please explain exactly what you are doing and exactly what happens. Thanks.

@g8up
Copy link

g8up commented May 26, 2018

I came across the same issue when I executed go run main.go.
Demo Repo

@VojtechVitek
Copy link

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

amyangfei added a commit to amyangfei/go-logster that referenced this issue Oct 24, 2018
In order to solve following exception in `go test`
    runtime.main_main·f: relocation target main.main not defined
    runtime.main_main·f: undefined: "main.main"
Can refer to golang/go#20312
amyangfei added a commit to amyangfei/go-logster that referenced this issue Oct 24, 2018
In order to solve following exception in `go test`
    runtime.main_main·f: relocation target main.main not defined
    runtime.main_main·f: undefined: "main.main"
Can refer to golang/go#20312
@golang golang locked and limited conversation to collaborators Jul 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

13 participants