dsfsdf5646 2018-07-20 02:02
浏览 28
已采纳

Go插件中没有符号

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
", err)
        os.Exit(1)
    }

    fmt.Printf("%+v
", 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?

  • 写回答

1条回答 默认 最新

  • dongzhi6463 2018-07-20 14:03
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算