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

how to use pluginpath in golang 1.13 or golang 1.14 #39142

Closed
ztgameming opened this issue May 19, 2020 · 3 comments
Closed

how to use pluginpath in golang 1.13 or golang 1.14 #39142

ztgameming opened this issue May 19, 2020 · 3 comments

Comments

@ztgameming
Copy link

@ztgameming ztgameming commented May 19, 2020

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

$ go version
go version go1.14.3 linux/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/zhangyinming/goproject"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/root/zhangyinming/goBin/go1.14/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/zhangyinming/goBin/go1.14/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/zhangyinming/securityProject/packServer/apk-pack-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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build258459112=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I use plugin mode to build a dynamic library with custom definition pluginpath,but when load in another program it display can't find the symbol.  It works weel in golang 1.12.

    go build -buildmode=plugin --ldflags="-pluginpath=plugin_version_1" -o server01.so exported.go
plugin.Open("soDir/server01"): could not find symbol Init: /mydir/soDir/server01.so: undefined symbol: plugin_version_1.Init

What did you expect to see?

 should load normal

What did you see instead?

nothing
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented May 20, 2020

Could you provide an example of the code that produced the error?

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 20, 2020

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this Jun 20, 2020
@folivora-ice
Copy link

@folivora-ice folivora-ice commented Oct 18, 2020

Could you provide an example of the code that produced the error?
I also encountered the same problem
this is my directory structure:

test/
  - main.go
  - go.mod
  - plugins/
    - helloworld/
      - main.go
// test/plugins/helloworld/main.go

package main

import (
	"fmt"
)

func init() {
	fmt.Println("plugin hello has been loaded")
}

func Hello(name string) {
	fmt.Println("Hello " + name)
}
// test/main.go
package main

import (
	"fmt"
	"plugin"
)

func getPluginMethod(pluginPath, method string) (interface{}, error) {
	plugin, err := plugin.Open(pluginPath)
	if nil != err {
		return nil, err
	}

	return plugin.Lookup(method)
}

func main() {
	fmt.Println("begin main")

	helloSymbol, err := getPluginMethod("./lib/hello.so", "Hello")
	if nil != err {
		fmt.Println(err.Error())
		return
	}
	hello, ok := helloSymbol.(func(name string))
	if !ok {
		fmt.Println("hello must be func(string)")
		return
	}

	hello("World")
}

build command

go build -o lib/hello.so --buildmode=plugin --ldflags="-pluginpath=hello" test/plugins/helloworld

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/projects/go/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/projects/go/gopath"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/opt/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/projects/go/plugin/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build693790146=/tmp/go-build -gno-record-gcc-switches"

go version

go version go1.15.3 linux/amd64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.