9

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.

Ben
  • 165
  • 2
  • 5
  • Are you releasing the handle to your dll? – Felipe Jan 09 '12 at 17:19
  • You probably need to be somewhat more specific about which platform (Linux?) and which version you are using. It is likely to matter for this sort of issue. – Jonathan Leffler Jan 09 '12 at 17:40
  • @Komyg: I am using dlclose(handle), so I am assuming that the handle is released doing so... – Ben Jan 09 '12 at 17:52
  • @Jonathan: I am using g++ 4.2.3, on linux ubuntu 10.04 – Ben Jan 09 '12 at 17:54
  • 1
    You might want to keep an eye on [Unload dynamic library needs two dlclose calls](http://stackoverflow.com/questions/8793099/unload-dynamic-library-needs-two-dlclose-calls), which is related but definitely not a direct duplicate as it is referring to MacOS X. Is there any chance that your executable loads the library anyway? Does `ldd your_executable` list the library? – Jonathan Leffler Jan 09 '12 at 18:19
  • @Ben : I have the same issue. I tried removing RTLD_GLOBAL, but still facing the same issue. Do you have any other suggestion to try out? – A R Sep 09 '15 at 05:55

1 Answers1

4

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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
cateof
  • 6,608
  • 25
  • 79
  • 153
  • "loaded library uses a symbol due to the RTLD_GLOBAL". indeed, I had symbols of a .a embedded when linking that were probably called back and preventing the library to close... I think I can verify if a lib unloaded using dlopen(RTLD_NOLOAD) on it to check out the library has unloded correctly – Ben Jan 10 '12 at 15:40