Max
Max

Reputation: 15955

No symbols in Go plugin

I am trying to use Go's plugin system. Even with a very basic example, I'm unable to find any symbols in a compiled plugin. My setup looks like this:

/Users/blah/test-workspace/
  src/
    main/
      main.go
    plug/
      plug.go

plug.go looks like this:

package main

type B struct {}

func main() {}

From the /Users/blah/test-workspace/ directory, I build this using:

GOPATH="/Users/blah/test-workspace" go build -buildmode plugin plug

This produces p.so inside the root of the GOPATH. Next I try to load this plugin via main/main.go:

package main

import (
    "fmt"
    "plugin"
    "os"
)

func main() {
    plugin, err := plugin.Open("plug.so")
    if err != nil {
        fmt.Printf("Error: %+v\n", err)
        os.Exit(1)
    }

    fmt.Printf("%+v\n", plugin)
}

The output of this code is:

&{pluginpath:plug err: loaded:0xc420088060 syms:map[]}

As you can, the symbol map is empty. What am I doing wrong?

Upvotes: 0

Views: 707

Answers (1)

Mr_Pink
Mr_Pink

Reputation: 109347

From the plugin docs

A symbol is any exported variable or function

You need to add an exported variable or function in order for your plugin to work.

Upvotes: 1

Related Questions