Reputation: 21
I am developing a project where plugins are built on startup:
func BuildPlugin(path *string) error {
buildGo := "go"
buildArgs := []string{
"build",
"-buildmode=plugin",
"-o",
filepath.Join(*path, "ext/ext.so"),
filepath.Join(*path, "ext/ext.go"),
}
cmd := exec.Command(buildGo, buildArgs...)
_, err := cmd.Output()
if err != nil {
return err
}
return nil
}
When I run the program, the plugins load successfully, however when I run the tests, I get the following error:
fsm_test.go:34: plugin.Open("../examples/00_test/ext/ext"): plugin was built with a different version of package github.com/jaimeteb/chatto/fsm
I have read some solutions for similar problems but none have worked yet.
This is the project in question: github.com/jaimeteb/chatto
Upvotes: 2
Views: 2057
Reputation: 41
Go plugins are really nifty, but their biggest drawback is that the versions of Go that both the plugin and consumer binaries are built with have to match exactly. This is really the biggest thing that's kept me from using them more often, opting instead for RPC-based plugin libraries like hashicorp/go-plugin
.
If you opt to keep going with Go plugins, you'll need to rebuild the project's plugins whenever you change Go's versions, or maybe even whenever you build your consuming project.
Upvotes: 4