5

If I open a library using dynamic loading in C++, can I later reload an updated version of that same library? I would test this myself, but I am curious about it's feasibility before I start looking into this as a potential solution to something I am working on.

In case it makes a difference, I am running on Linux. Being able to make it work on other operating systems would be nice, but is not a requirement.

user396404
  • 2,759
  • 7
  • 31
  • 42
  • I see no reason why you can't test it with `Hello world` before testing it with your actual code. It can't take more than 5 minutes. – Mahmoud Al-Qudsi Jan 17 '13 at 04:04
  • Because I have not worked with dynamic loading before in the past, and I want to make sure there aren't situations that I am not foreseeing. Some of the worst errors are when things seem to function properly after basic testing, and then break down due to unforeseen situations. – user396404 Jan 17 '13 at 04:07
  • 2
    Make sure the library has (1) returned all OS resources (2) delete'd all memory allocated (3) removed all pointers into the library, before unloading the library. – brian beuning Jan 17 '13 at 04:38
  • Thank you. I will make sure to watch for those things. – user396404 Jan 17 '13 at 16:42

2 Answers2

3

Technically speaking you most certainly can — there is nothing that prevents you from doing so. This is how dlopen()/dlclose() work in user space. This is also how kernels load and unload dynamic modules, etc. In practice, though, a poorly written shared object or a host program may introduce disastrous side effects rendering the process (or the kernel, in case you are talking about a kernel module) unusable.

0

As already answered, this should work. About dlopen / dlclose clean usage in C++, you should have a look at this answer C++ Dynamic Shared Library on Linux.

Xavier Lamorlette
  • 1,152
  • 1
  • 12
  • 20