[Development] Explicit linking vs dlopen/dlsym

Kevin Kofler kevin.kofler at chello.at
Sun Nov 23 08:22:28 CET 2014


Pau Garcia i Quiles wrote:
> Today I installed an snapshot of Qt 5.4.0 for Linux x86 on my Kubuntu
> 14.04 and found a problem: it links to libudev.so.0, while Ubuntu 14.04
> provides libudev.so.1.
> 
> I was wondering if it would be a good idea for Qt to move from explicit
> linking to dlopen/dlsym. That would help supporting different versions of
> a certain library, and support different codepaths at runtime depending on
> which one was found. Eg. libudev.so.0 or libudev.so.1, libstreamer-0.10.so
> or libgstreamer-1.0.so, etc

Sorry, but as distribution packagers, we really no NOT like dlopened 
libraries, for several reasons:
1. A dlopened library is not autodetected as a dependency by our package 
managers, and we therefore have to manually add Requires. If we forget, Qt 
either has reduced functionality or does not work at all (or the application 
does not work because Qt does not support the functionality it requires 
without the missing dependency).
2. If the library makes another API/ABI change, say, to libudev.so.2, who 
ensures that the dynamic loading code (a) finds the new library and (b) 
works with the changed API/ABI? With direct linking, this is easy: We just 
rebuild against the new library, and if it compiles and links, it works. And 
if not, we know exactly what changes are needed, unlike in the dlopen case 
where API mismatches are not detectable by the compiler nor the linker.
3. Where different library versions require entirely different code paths in 
Qt (e.g. for GStreamer), we would be carrying both code paths, when we 
actually KNOW at build time which version of the library will be available 
at runtime.
4. Unfortunately, when Qt adds support for a new library that can be 
dlopened, the default is almost always to dlopen it, which is a pain because 
it makes it easy to miss the needed explicit Requires (see point 1).

Therefore, in the distribution packages, we configure with -linked-* 
wherever possible, and IMHO that should be the default.

        Kevin Kofler




More information about the Development mailing list