[Interest] Is it ok to use QLibrary to load and unload different shared libraries in sequence?
Roland Winklmeier
roland.m.winklmeier at gmail.com
Thu Oct 25 09:03:32 CEST 2018
Thanks a lot for your response.
Am Mi., 24. Okt. 2018 um 17:20 Uhr schrieb Thiago Macieira <
thiago.macieira at intel.com>:
> > I got some strange behavior while debugging the above lines in QtCreator
> > (error message saying that "Command aborted" after the first unload and
> gdb
> > aborts). So I'm not sure if I do something totally wrong.
>
> 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.
> Things to watch out for:
> 1) The number of load() and unload() calls must be paired, since they
> control
> a refcount. Don't just destroy the QLibrary without unload().
>
This is done. The call to unload() is done explicitly before QLibrary is
destroyed (I keep QLibrary in a QScopedPointer that is reset after
unloading).
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.
> 3) make sure that no plugin was loaded that linked to that library or, if
> it
> was, unload it too (preferably, don't unload anything).
>
The libraries are only resolved in one line of code, so this should not be
a problem.
> 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?
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181025/c7d74c00/attachment.html>
More information about the Interest
mailing list