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

Most upvoted comments

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