# Installing Qt libraries on Linux

**URL:** https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524
**Category:** Usage
**Tags:** os:linux
**Created:** [July 9, 2020, 7:49am UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524 "2020-07-09T07:49:53Z")
**Posts on this page:** 10
**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 9, 2020, 7:49am UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/1 "2020-07-09T07:49:53Z")

</div>

Is there a way of using install(TARGETS… to install the Qt libraries, together with their namelinks, on Linux?

I’d expect the following to work, but it does not, and I don’t understand why:

```
# First locate the Qt installation
find_package(Qt5 COMPONENTS Core Gui Widgets Designer Test REQUIRED PATHS "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5" NO_DEFAULT_PATH)

# Verify that Qt5::Core is recognised as a target,
# and print out the location where its files were found
get_property(QT_CORE_INCLUDE_DIRS TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
list(GET QT_CORE_INCLUDE_DIRS 0 QT_CORE_MAIN_INCLUDE_DIR)
get_filename_component(QT_MAIN_DIR ${QT_CORE_MAIN_INCLUDE_DIR}/.. ABSOLUTE)
message("-- Qt version ${Qt5Core_VERSION_STRING} was located at ${QT_MAIN_DIR}")

set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTORCC ON)
set (CMAKE_AUTOUIC ON)

install(TARGETS Qt5::Core Qt5::Gui Qt5::Widgets
        LIBRARY
        DESTINATION myInstallDirectory)

```

When I run CMake on this script, the output is:

```
-- Qt version 5.12.5 was located at [...exactly where I expected to find it...]

CMake Error at configureQT5.cmake::[line no.] (install):
install TARGETS given target "Qt5::Core" which does not exist.

```

I’ve successfully used Qt5::Core as a target just a few lines previously in the file, so why does it suddenly not exist?

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [July 9, 2020, 8:07am UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/2 "2020-07-09T08:07:15Z")

</div>

`find_package()` provides you with imported targets. Those can be used for dependency propagation, linking, etc. but cannot be installed.

---

<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 9, 2020, 8:42am UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/3 "2020-07-09T08:42:23Z")

</div>

Thank you; but in that case, how _can_ I install them? I need to do so since my application depends on them.

‘install(FILES’ works all right, but doesn’t copy the namelinks over, and it seems I need these as well because the physical file is libQt5Core.so.5.12.5 but my application looks for libQt5Core.so.5.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [July 9, 2020, 2:22pm UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/4 "2020-07-09T14:22:00Z")

</div>

[https://cmake.org/cmake/help/v3.18/command/file.html?highlight=file#get-runtime-dependencies](https://cmake.org/cmake/help/v3.18/command/file.html?highlight=file#get-runtime-dependencies)

But when deploying it like that you should really look into snap or flatpak.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [July 9, 2020, 2:24pm UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/5 "2020-07-09T14:24:30Z")

</div>

Additionally, copying Qt libraries is really only part of the job. You also need plug-ins, resources, etc. There is a tool for Qt Linux deployment, if you don’t want to do it all yourself.

---

<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 9, 2020, 8:00pm UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/6 "2020-07-09T20:00:41Z")

</div>

I’ll have a go; but my concern is that I already know what the dependency is and I can install the library itself easily enough, it’s just that my application wants to link to the namelink and complains that it can’t find the library itself.

I either need to install the namelink, or figure out how to get the application to link to the library directly.

---

<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 9, 2020, 8:01pm UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/7 "2020-07-09T20:01:52Z")

</div>

The plugins are easy to do, and I have CMake generate a custom qt.conf file to tell my application where to find them.

I know about windeployqt, but I thought that the Linux version was still ‘unofficial’ and not supported.

---

<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: [November 11, 2020, 3:20pm UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/8 "2020-11-11T15:20:37Z")

</div>

You should be able to use [`file(GET_RUNTIME_DEPENDENCIES)`](https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies) to find the runtime libraries used by your targets. You can then install these (though the namelinks would need some extra work today).

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [November 12, 2020, 9:35am UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/9 "2020-11-12T09:35:19Z")

</div>

The `FOLLOW_SYMLINK_CHAIN` keyword of the `file(COPY)` or `file(INSTALL)` subcommands may help (keyword available since CMake 3.15), but you’d have to be installing your imported libraries with a custom install script to use it, which is perhaps more convoluted.

---

<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: [November 12, 2020, 9:55pm UTC](https://discourse.cmake.org/t/installing-qt-libraries-on-linux/1524/10 "2020-11-12T21:55:33Z")

</div>

What I actually did was this… First, I worked backwards from the Qt5::Core target to find the directory where the Qt installation had been found:

```
get_property(QT_CORE_INCLUDE_DIRS TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
list(GET QT_CORE_INCLUDE_DIRS 0 QT_CORE_MAIN_INCLUDE_DIR)
get_filename_component(QT_MAIN_DIR ${QT_CORE_MAIN_INCLUDE_DIR}/.. ABSOLUTE)	

```

Then in the first instance I did what’s described [here](https://discourse.cmake.org/t/linking-to-installed-qt-libraries-on-linux/1535).

That didn’t quite get me out of the woods, though, because especially once I’d installed PySide2 as well and realised that people could now write scripts using _any_ components of Qt, not just the ones I was using in my C++ application, I decided I’d better just go for it and install the whole Qt directory:

```
    install(DIRECTORY ${QT_MAIN_DIR}/lib/
            DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
            USE_SOURCE_PERMISSIONS)    
    install(DIRECTORY ${QT_MAIN_DIR}/plugins/imageformats/
            DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/qt/plugins/imageformats
            USE_SOURCE_PERMISSIONS) 
    install(DIRECTORY ${QT_MAIN_DIR}/plugins/platforms/
            DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/qt/plugins/platforms
            USE_SOURCE_PERMISSIONS) 

```

This works nicely now.
