6

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.

4
  • 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. Commented Jan 17, 2013 at 4: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. Commented Jan 17, 2013 at 4: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. Commented Jan 17, 2013 at 4:38
  • Thank you. I will make sure to watch for those things. Commented Jan 17, 2013 at 16:42

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.