New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugin: with net/http causes "plugin was built with a different version of package" #20248
Comments
This generally works. The only thing that looks different in your report than my local tests is GOARCH=386. I'll give that a try when next I can. |
It works until I import net/http in the plugin - then plugin.Open fails. My system is 32-bit Linux. I also just tried the following: GOARCH= go build -buildmode=plugin -o plugin.so plugin.go with same result: 2017/05/05 00:25:33 Could not open plugin: plugin.Open: plugin was built with a different version of package vendor/golang_org/x/text/unicode/norm |
I don't think this has anything to do with net/http. I bet importing any cgo package is what causes the failure. Try os/user or net, for example. |
No, it looks to be something with net/http. I tried 2 plugins - 1 importing "net" and the other importing "os/user" and plugin.Open() succeeded. net:
os/user:
I suspect something to do with the combination of:
|
I got a similiar problem with a another local package. It looks like: // Original Code from https://github.com/matrix-org/go-neb/blob/b1fe968f832996c219dfb60d718d36220ef3c91c/src/github.com/matrix-org/go-neb/types/service.go
// It is LICENSED under Apache 2.0
package types
// A Service is the configuration for a bot service.
type Plugin interface {
// Return the user ID of this service.
PluginID() string
// Return if Service requires Web.
Web() bool
}
// DefaultPlugin NO-OPs the implementation of optional Plugin interface methods. Feel free to override them.
type DefaultPlugin struct {
id string
web bool
}
// NewDefaultPlugin creates a new Plugin with implementations for pluginID(), serviceName() and web()
func NewDefaultPlugin(pluginID string, web bool) DefaultPlugin {
return DefaultPlugin{pluginID, web}
}
func (s *DefaultPlugin) PluginID() string {
return s.id
}
func (s *DefaultPlugin) Web() bool {
return s.web
} and gets imported into the file I use it in and imported in my main function that I use to run the plugin from. both are compiled directly after each other. Plugin Code: package main
import (
"fmt"
"gitlab.com/IRSH/irshGoFramework/types"
)
// pluginName of the Web Plugin
const pluginName = "web"
type pluginStruct struct {
types.DefaultPlugin
}
func (g pluginStruct) Greet() {
fmt.Println("Hello Universe")
}
// Define Plugin (Web=false as it otherwise would create a dependency loop)
var Plugin = &pluginStruct{
DefaultPlugin: types.NewDefaultPlugin(pluginName, false),
} Main/Loader Code: package main
import (
"fmt"
"gitlab.com/IRSH/irshGoFramework/types"
"os"
"plugin"
)
func main() {
plug, err := plugin.Open("./plugins/web.so")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// 2. look up a symbol (an exported function or variable)
// in this case, variable Greeter
symGreeter, err := plug.Lookup("Plugin")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// 3. Assert that loaded symbol is of a desired type
// in this case interface type Greeter (defined above)
var pluginModule types.Plugin
pluginModule, ok := symGreeter.(types.Plugin)
if !ok {
fmt.Println("unexpected type from module symbol")
os.Exit(1)
}
// 4. use the module
fmt.Println(pluginModule.PluginID())
} Edit: My go env output:
|
I am having a similar issue when testing go 1.9rc2 (same as the user above). The plugin part of the software I am working on works fine when using go 1.8.3, once switched to go1.9rc2 while keeping everything else the same (3rd party libraries all vendored, no exact env setting, pretty sure everything is using default value), I got the "plugin was built with a different version of package plugin" error when trying to open the plugin. As @bradfitz mentioned above, the plugin I am trying to build does import a package that uses cgo. |
@lni want to try out https://golang.org/cl/61071 and see if it helps? |
I believe this was fixed at tip by https://golang.org/cl/63693. It's a little concerning that the original report mentions 1.8, however I haven't been able to replicate that bug at HEAD. Please comment if you're still seeing this with HEAD and I'll reopen this. |
@crawshaw I am confirming, but it looks like I am hitting this on 1.8.3. Upgrading right now isn't an option (our systems crash on 1.9 due to some threading issues). It looks like I'll need to backport the above CL 😿 to 1.8... |
What version of Go are you using (
go version
)?go version go1.8.1 linux/386
What operating system and processor architecture are you using (
go env
)?GOARCH="386"
GOBIN=""
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/Go/_lib"
GORACE=""
GOROOT="/root/go"
GOTOOLDIR="/root/go/pkg/tool/linux_386"
GCCGO="gccgo"
GO386=""
CC="gcc"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build202967868=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
plugin.go:
package main
main.go:
package main
go build -buildmode=plugin -o plugin.so plugin.go
go run main.go
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
What did you expect to see?
pg=...something...
What did you see instead?
2017/05/04 12:34:36 Could not open plugin: plugin.Open: plugin was built with a different version of package vendor/golang_org/x/text/unicode/norm
The text was updated successfully, but these errors were encountered: