go: plugin: runtime.main_main·f: undefined: "main.main"(buildmode=plugin)
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!
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 18 (5 by maintainers)
Commits related to this issue
- plugins: generate dummy main function for plugins to fix go#20312 https://github.com/golang/go/issues/20312 License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch> — committed to ipfs/kubo by Kubuxu 7 years ago
- Skip the plugin packages in travis 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 s... — committed to nelsam/vidar by nelsam 7 years ago
- Fix test case in go 1.8 and 1.9 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... — committed to amyangfei/go-logster by amyangfei 6 years ago
- Fix test case in go 1.8 and 1.9 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... — committed to amyangfei/go-logster by amyangfei 6 years ago
In my case I had not defined a function called main i.e.
func main(){}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.You need to add
func main() {}to your plugin.my hot-update based on plugin for go has succeeded! ^ ^
@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