8

I have an application that loads plugins on startup (daemon). In a subpackage (daemon/interfaces), I have a few interfaces that plugins for this program should use.

This means that the main program also gets imported by the plugin.

I am using Go modules (for both the main program and the plugin) to fix the versions, and I can see in go.mod that it is using the latest version of the main program for the plugin.

I can build them both fine, but when I load the plugin it gives me an error saying

 panic: plugin.Open("plugins/my-plugin"): plugin was built with a different version of package daemon/interfaces

I am using Go 1.12.7 to build both of the packages.

Pieterjan
  • 445
  • 6
  • 23

2 Answers2

4

I fixed this by adding a replace statement to my plugin go.mod file

module github.com/user/plugin

go 1.12

require (
    github.com/user/daemon v1.1.1
)

replace github.com/user/daemon v1.1.1 => ../local/path/to/daemon/

It also helps when you are building the project from outside of the directory where the source code is in by using the full name of the project (go build github.com/user/project/)

There is a related Github issue on the Golang repository that you can find here

Pieterjan
  • 445
  • 6
  • 23
0

Apparently, the issue is still open. The issue opener presented the workaround, which I was able to use. Please look at the history lines below for details.

git clone https://github.com/zimnx/central.git
git clone https://github.com/zimnx/plugins.git
cd central/
go clean -modcache
git checkout v1.0.0
go install -a
cd ../plugins/
rm go.mod 
go mod init github.com/zimnx/plugins
echo '' >> go.mod
echo 'replace github.com/zimnx/central => ../central' >> go.mod
go build -buildmode=plugin -o plugin.so
central plugin.so 

Works for me. Mistery still... :) The output has been saved for the most curious.

Did Alik
  • 199
  • 2
  • 7