Linking to installed Qt libraries on Linux

I’m having persistent difficulties installing and linking to Qt libraries on Linux.

In previous questions here and here, I asked about how to install Qt libraries along with their namelinks, since the library name searched for by the linker (libQt5Core.so.5) was a symlink to libQt5Core.so.5.12.5 rather the file itself.

I had some success with:

install(CODE "file(COPY ${QT_MAIN_DIR}/lib/libQt5Core.so DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} FOLLOW_SYMLINK_CHAIN)")

…but that didn’t quite work because the only symlink it copied was libQt5Gui.so -> libQt5Gui.so.5.12.5 rather than libQt5Gui.so.5. I know that libQt5Gui.so.5 is what I want because if I go to the installation directory and manually type:

ln -s libQt5Core.so.5.12.5 libQt5Core.so.5

…then everything works as it should.

So, if I can’t get CMake to generate a link for libQt5Core.so.5 automatically, it looks like what I need to do is to get my application to link to either libQt5Core.so or libQt5Core.so.5.12.5 instead of libQt5Core.so.5. But I can’t see how I can control that.

Please can someone advise?

The .so is the link name (what -lfoo looks for). The .so.5 is the “soname”. This is the ABI-compatibility name that is used when loading the library. The actual implementation lives in the .so.5.12.5 library. This allows the ABI compat link to “float” between multiple installations as needed. You’re always going to have the soname embedded when you make a library (the impl has the soname in it and that is what is copied into the binary as a DT_NEEDED entry. I’d recommend installing libQt5Core.so* rather than trying to guess what is there.

Yes, that’s it. That’s the solution:

install(CODE "file(COPY ${QT_MAIN_DIR}/lib/libQt5Core.so.5  
                   DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
                   FOLLOW_SYMLINK_CHAIN)")

…and everything works as it ought to. Even though libQt5Core.so.5 is a symlink rather than the actual file, it installs the actual file and its links correctly, and the application finds its libraries successfully after installation.

Thank you.