go: plugin: panic: plugin was built with a different version of package
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.11 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GOARCH=“amd64” GOBIN=“/Users/juhwany/go_workspace/bin” GOCACHE=“/Users/juhwany/Library/Caches/go-build” GOEXE=“” GOFLAGS=“” GOHOSTARCH=“amd64” GOHOSTOS=“darwin” GOOS=“darwin” GOPATH=“/Users/juhwany/go_workspace” GOPROXY=“” GORACE=“” GOROOT=“/usr/local/go” GOTMPDIR=“” GOTOOLDIR=“/usr/local/go/pkg/tool/darwin_amd64” GCCGO=“gccgo” CC=“clang” CXX=“clang++” CGO_ENABLED=“1” GOMOD=“/Users/juhwany/gos/go_server/go.mod” CGO_CFLAGS=“-g -O2” CGO_CPPFLAGS=“” CGO_CXXFLAGS=“-g -O2” CGO_FFLAGS=“-g -O2” CGO_LDFLAGS=“-g -O2” PKG_CONFIG=“pkg-config” GOGCCFLAGS=“-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mk/2tyywdsn0jq6l0vl8094tss80000gp/T/go-build380269681=/tmp/go-build -gno-record-gcc-switches -fno-common”
What did you do?
-
Clone the blow repo in each directory. (not under GOPATH) server (main program) : https://github.com/juhwany/go_server plugin : https://github.com/juhwany/go_plugin
-
On same machine, build server & plugin in each directory Build server :
go build -o mainBuild plugin :go build -buildmode=plugin -o plugin.so -
Copy plugin.so to server directory and run ./main
-
See error message when main program try to open plugin.
panic: plugin.Open("plugin"): plugin was built with a different version of package github.com/juhwany/go_server/v2/apis
What did you expect to see?
Main program should load plugin.so successfully. I could not understand why it fails even though the referenced package version is same between main program and plugin. Am I using plugin in wrong way?
What did you see instead?
plugin was built with a different version of package error message
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 33
- Comments: 33 (7 by maintainers)
Commits related to this issue
- Fix memory plugin build easyjson does not work with main packages. Workaround changing the package name as suggested in https://github.com/mailru/easyjson/issues/236 Some code has been moved from sk... — committed to datadope-io/skydive-plugins by adrianlzt 4 years ago
- Fix memory plugin build easyjson does not work with main packages. Workaround changing the package name as suggested in https://github.com/mailru/easyjson/issues/236 Some code has been moved from sk... — committed to datadope-io/skydive-plugins by adrianlzt 4 years ago
- use -trimpath to build, to avoid https://github.com/golang/go/issues/27751 — committed to knipknap/grpc-server-go by knipknap 4 years ago
- due to https://github.com/golang/go/issues/27751 Golang plugins are too fragile; switch to compiling a monolith instead :-( — committed to knipknap/grpc-server-go by knipknap 4 years ago
- feature/WEOS-482 trying to get tests to pass * updated mocks * ran into issue becuase we're using go modules so when tests are run they don't match the version of the plugin https://github.com/golang... — committed to wepala/weos-controller by akeemphilbert 4 years ago
- feature/WEOS-482 Parse environment variables in api config * Made so that environment variables are expanded on the api config * Skipped tests that load the so. There are issues with compiling and lo... — committed to wepala/weos-controller by akeemphilbert 4 years ago
- tests will not work because the plugin system has an error loading at runtime ref: https://github.com/golang/go/issues/27751 Signed-off-by: Avelino <avelinorun@gmail.com> — committed to prest/prest by avelino 2 years ago
- tests will not work because the plugin system has an error loading at runtime ref: https://github.com/golang/go/issues/27751 Signed-off-by: Avelino <avelinorun@gmail.com> — committed to prest/prest by avelino 2 years ago
added -trimpath and the error moved from our microservice dependency lib to now internal/cpu:
@dhaimeen We’ve used the Go plugin API for quite a while now (over a year) and the error “different version of package internal/cpu” occurs when you’ve not used the
-trimpathflag on both the shared object you build (plugin) and the main binary. Both bundle a copy of the Go runtime (although there’s an open issue on the tracker about not packaging a copy of the Go runtime with plugin code). Hope this helps.@bcmills I got caught up on this one with modules - the problem can occur when you import a package from the same module in the “loader,” and you import the same package but from a different module in the “plugin.”
In #28983, @bcmills suggests to build plugins from within the main module.
I have a collection of Go plugins I need to package and distribute. When building and running on my machine everything works as expected. However plugins don’t work on other machines.
Here is the command I execute:
I tried running the parent application calling the plugins both with and without
-trimpath. Nothing works.How can I fix this behavior?
I have basically tried everything and in the end I have this error:
plugin was built with a different version of package internal/goarch". I am using exact same dependencies, go version, built environments, flags, etc…Thank you @paralin , but my problem is … very ennoyinh.
Package A include C version 1.1 ( go mod used ).
Package B ( the plugin ) include C version 1.1 go mod used.
Result, Plugin B was buillt with a different version of C.
My “workaround” was to remove the go.mod used in the B package to make it works. Very dirty solution in my opinion.
Apparently disabling optimizations and inlining
-gcflags="all=-N -l"“resolves” the issue for me, but the output files are huge 😦go build -buildmode=plugin -gcflags="all=-N -l" -o plugins/test.so plugins/test.goOk, I think we have determined the difference:
Successful:
Unsuccessful:
Are there any ways to determine why the latter fails to produce the same output as the former?
Thanks!
Hey @dhalman,
could you post the link to the open source syncing solution of yours. I find developing any a bit non-trivial plugin for any a bit non-trivial app a total nightmare. Maybe your solution might help me out. 😃
Cheers
We have developed an open source solution for syncing go.mod repositories across large projects with internal dependencies. We find it especially useful for managing large collections of plugins along with their private imports.
Happy to share it if requested, but would not want to advertise in this forum
We are experiencing this issue after implementing go.mod in both the server and plugin