[Interest] Is it ok to use QLibrary to load and unload different shared libraries in sequence?

Thiago Macieira thiago.macieira at intel.com
Fri Oct 26 18:21:00 CEST 2018

On Thursday, 25 October 2018 00:03:32 PDT Roland Winklmeier wrote:
> > The problem might be a number of different things. In general, don't
> > unload
> > libraries. If your design requires it, rethink and redesign.
> It was more like a safety feature. Technically I don't have to unload the
> other dlls. I could also keep the previous one loaded, but I was concerned
> about potential conflicts. I'm not an expert in these things, but if there
> are two or even more shared libraries loaded into the same process that are
> almost identical and therefore many common symbol names (the library is
> proprietary so I have no way to check, but the publisher says so) can I run
> into issues? If not, I would not bother unloading them.

Loading two versions of the same library is even worse and far more likely to 
cause problems. When I suggested you redesign, that would be part of it and 
you'd need to figure out a way so that you only ever load one and don't unload 

A process separation idea comes to mind.

> 2) make sure that there are no pointers remaining to any function, constant
> > or
> > variable left that points to something in that library
> Also done. All resolved function pointers are cleared and set to nullptr
> before unloading.

No "new'ed" objects that it may have allocated that need "delete"? Note that 
on Windows, different runtimes have different malloc() pools. Polymorphic 
classes have pointers to the vtable, which is in the DLL. And so forth.

> > 4) make sure the libraries don't do anything stupid in their DllMain
> > unattach
> > call.
> That's hard to check since I don't have the source code. Or is there
> another way to check that?

There are ways, but difficult ones. You'd have to debug through the assembly 
to figure out what it is doing.

> Just as a side note: When running without debugger, everything is fine.
> Only the during debugging, I see the error message. I might just try in a
> very simple test case, whether I can reproduce it with gdb.


Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Interest mailing list