I'm not sure what I'm doing wrong or if I understood at all the plugin 
package of 1.8


I have a plugin like the example  exampleplugin/main.go (build with "go 
build -buildmode=plugin")

package main

// // No C code needed.
import "C"

import "fmt"

var V int

func F() { fmt.Printf("Hello, number %d\n", V) }




Now, I have a "plugin manager" , pluginmanager/pluginmanager.go

package pluginmanager

import "plugin"

func Load(path string) {
    p, err := plugin.Open(path)
    if err != nil {
        panic(err)
    }
    f, err := p.Lookup("F")
    if err != nil {
        panic(err)
    }
    f.(func())()
}



And finally, my main.go program

package main

import (
    "path/to/my/pluginmanager"
    "plugin"
)

func main() {
    pluginmanager.Load("exampleplugin/exampleplugin.so")
}


This doesn't work and shows the error : plugin.Open: plugin was built with 
a different version of package runtime
Sometimes, instead of runtime it shows another package, like math, errors, 
...


BUT, if I load the plugin in the main.go program... it works:

package main

import (
    "path/to/my/pluginmanager"
    "plugin"
)

func main() {
    plugin.Open("exampleplugin/exampleplugin.so")
    pluginmanager.Load("exampleplugin/exampleplugin.so")
}

This works as expected, and exampleplugin.F() is called. I'm not sure what 
I'm doing wrong or if I missed something. I'm using : go version devel 
+7dc97d9 Sat Nov 19 04:31:36 2016 +0000 linux/amd64

Also, I kind of understand that the plugin and the main program should use 
the same version of a package, very limiting, since you may not know which 
version a plugin used, but it's ok. Or is there any other way to do it?

Regards


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to