1
yanqiyu 7 小时 1 分钟前
我觉得最简单的办法是在你的动态库里面加一个构造和析构会打 log 的对象看看这东西被析构了吗,如果不是的话去 gdb 给 dlopen 打断点看看是不是有别的没注意到的地方 dlopen 了
另外确定你们的环境不是 musl ?这东西的 dlclose 我记得是假的 |
![]() |
3
ysc3839 6 小时 27 分钟前 via Android
还是提供初始化和卸载函数吧
|
![]() |
4
seers 6 小时 18 分钟前 via Android
dlclose 后检查下 soinfo 链,看看是不是确实关闭了
|
![]() |
5
Noicdi 3 小时 58 分钟前
> 可以定义一个或多个在共享库被加载和卸载时自动执行的函数,这样在使用共享库时就能够完成一些初始化和终止工作了。不管库是自动被加载还是使用 dlopen 接口(参见 42.1 节)显式加载的,初始化函数和终止函数都会被执行。
> > 《 Linux/Unix 系统编程手册》 42.2 初始化和终止函数 那我的第一反应就是你提供全局变量的析构函数,注册到终止函数里,库被卸载的时候去析构。但是又考虑到库没被卸载。 > Shared objects may export functions using the __attribute__((constructor)) and __attribute__((destructor)) function attributes. Constructor functions are executed before dlopen() returns, and destructor functions are executed before dlclose() returns. A shared object may export multiple constructors and destructors, and priorities can be associated with each function to determine the order in which they are executed. See the gcc info pages (under "Function attributes") for further information. > > man dlopen 但是这里又说 `destructor functions are executed before dlclose() returns`,那试一试? |
![]() |
6
Noicdi 3 小时 53 分钟前
|
7
Ainokiseki OP |
![]() |
8
passive 1 小时 8 分钟前 via Android
计数器只是一个原因
dlclose 并不会卸载 so ,前两天 hackernews 上刚有讨论 |