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 · 7 comments
Closed

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

ztgameming opened this issue May 19, 2020 · 7 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@ztgameming
Copy link

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

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

@davecheney davecheney added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 20, 2020
@gopherbot
Copy link

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.)

@linsanzhu
Copy link

linsanzhu 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

@ray2011
Copy link

ray2011 commented Mar 1, 2021

@ztgameming @folivora-ice did you solve this problem, How can I solve it?

@YankunLi
Copy link

@ztgameming @folivora-ice did you solve this problem, How can I solve it?

@YIDWang
Copy link

YIDWang commented May 7, 2022

The same question in go version go1.17.9 darwin/amd64

@ray2011
Copy link

ray2011 commented May 9, 2022

The same question in go version go1.17.9 darwin/amd64

dont use pluginpath option, just copy code to different directory.

@golang golang locked and limited conversation to collaborators May 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

8 participants