C++: dlclose doesn't unload the shared library

爱⌒轻易说出口 提交于 2019-12-18 04:46:21

问题


I have a shared library loaded using dlopen (with the flags RTLD_NOW | RTLD_GLOBAL ). If this library is using functions from the main program, then it does not unload. So I end up with the same code for this shared lib, even if I unloaded (using dlclose), changed, compiled, (re)load it.

My goal is actually to reload the same library after making changes to it, so that I do not have to relaunch the whole program to test out my code.

I am using g++ 4.2.3, on Linux Ubuntu 10.04.

(edit)

solved:

"loaded library uses a symbol due to the RTLD_GLOBAL". Indeed, I had symbols of another .a embedded when linking that were probably called back and preventing my library to close... I think it's possible to verify that a lib unloaded using dlopen(...,RTLD_NOLOAD) to check out the library has unloaded correctly.


回答1:


The function dlclose() decrements the reference count on the dynamic library handle. If the reference count drops to zero and no other loaded libraries use symbols in it, then the dynamic library is unloaded.

Also the RTLD_NODELETE (upon dlopen) makes dlclose not to unload the library.

Since you have not used RTLD_NODELETE, most probable is that a loaded library uses a symbol due to the RTLD_GLOBAL.



来源:https://stackoverflow.com/questions/8792363/c-dlclose-doesnt-unload-the-shared-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!