# Linking to installed Qt libraries on Linux

**URL:** https://discourse.cmake.org/t/linking-to-installed-qt-libraries-on-linux/1535
**Category:** Usage
**Created:** [July 10, 2020, 1:30pm UTC](https://discourse.cmake.org/t/linking-to-installed-qt-libraries-on-linux/1535 "2020-07-10T13:30:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [July 10, 2020, 1:30pm UTC](https://discourse.cmake.org/t/linking-to-installed-qt-libraries-on-linux/1535/1 "2020-07-10T13:30:21Z")

</div>

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

In previous questions [here](https://discourse.cmake.org/t/installing-versioned-qt-libraries-with-namelinks-on-linux/1499) and [here](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524), 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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 10, 2020, 1:51pm UTC](https://discourse.cmake.org/t/linking-to-installed-qt-libraries-on-linux/1535/2 "2020-07-10T13:51:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [July 10, 2020, 2:37pm UTC](https://discourse.cmake.org/t/linking-to-installed-qt-libraries-on-linux/1535/3 "2020-07-10T14:37:20Z")

</div>

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.
