栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

Golang无法加载指定plugin错误:cannot load plugin xxxx.so

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Golang无法加载指定plugin错误:cannot load plugin xxxx.so

Golang无法加载plugin错误:cannot load plugin xxxx.so

有的同学会疑问自己第一次加载的时候成了,随后发现一模一样的代码再运行一次就报错plugin加载失败了,这是一个很基础的错误,其实阅读过文档就会知道为什么会产生这样的错误了

When a plugin is first opened, the init functions of all packages not
already part of the program are called. The main function is not run.
A plugin is only initialized once, and cannot be closed.

意思很明显,只能使用plugin.Open加载一次,并且这是不能被关闭的(ps:plugin的所有操作都保障线程安全)

也就是说你只要成功加载了一次,在该进程中和其它的进程再次调用Open尝试加载就会报错(但依然会成功获取到我们想要的库指针)

下面是plugin.Open的描述

Open opens a Go plugin. If a path has already been opened, then the
existing *Plugin is returned. It is safe for concurrent use by
multiple goroutines.

那么解决的办法就是利用recover()接收error,保证接下来的代码继续正常执行

defer func() {
	if err := recover(); err != nil {
		fmt.Println("plugin had been opened")
	}
}()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/944415.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号