Skip to content
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: different version of package main #31048

Open
lxstorm opened this issue Mar 26, 2019 · 2 comments

Comments

Projects
None yet
4 participants
@lxstorm
Copy link

commented Mar 26, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lx/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lx/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/7k/r2p50mb149ngfkbmdw9tdqhc0000gp/T/go-build367373739=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I write a demo to test the go plugin, My work directory structure is

|____gen
| |____src
| | |____main
| | | |____main.go
|____plugin_name.so
|____build.sh
|____main.go

main.go

package main

import "plugin"

func main() {
	p, err := plugin.Open("plugin_name.so")
	if err != nil {
		panic(err)
	}
	v, err := p.Lookup("V")
	if err != nil {
		panic(err)
	}
	f, err := p.Lookup("F")
	if err != nil {
		panic(err)
	}
	*v.(*int) = 7
	f.(func())()
}

gen/src/main/main.go

package main

import "fmt"

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

build.sh

DIRPATH=$(dirname $0)
GOPATH=$(cd "${DIRPATH}/gen"; pwd)

export GOPATH
cd ${GOPATH}/src/main
go build -v -o plugin_name.so  -buildmode=plugin
mv plugin_name.so ${GOPATH}/..

What did you expect to see?

sh ./build.sh
go run main.go

I expect to see the main.go load the plugin successfully and print line.

What did you see instead?

panic: plugin.Open("plugin_name"): plugin was built with a different version of package main

goroutine 1 [running]:

main.main()
	/Users/lx/go/src/testZoom/tplugin/main.go:8 +0x38b
exit status 2

Why the main package is a different version, howerver if I modify the build.sh to

go build -v -o plugin_name.so  -buildmode=plugin main.go

Then go run main.go load so successfully.

How can the main package be a different version and why the second solution success?

@Kings-gee

This comment has been minimized.

@lxstorm lxstorm changed the title plugin different version of package main plugin: different version of package main Mar 26, 2019

@katiehockman

This comment has been minimized.

Copy link
Contributor

commented Apr 29, 2019

@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Apr 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.