# Qt5 component library not copied to CMAKE\_RUNTIME\_OUTPUT\_DIRECTORY

**URL:** https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461
**Category:** Code
**Tags:** os:windows
**Created:** [January 7, 2020, 4:48pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461 "2020-01-07T16:48:53Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [January 7, 2020, 4:48pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/1 "2020-01-07T16:48:53Z")

</div>

Under Windows, CMake sees the following:

```auto
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/$<CONFIG>)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Network Concurrent)
target_link_libraries(mylib
    PRIVATE
    ${Qt5Network_LIBRARIES}
    ${Qt5Gui_LIBRARIES}
    ${Qt5Widgets_LIBRARIES}
    ${Qt5Core_LIBRARIES}
    )

```

After `cmake`, `cmake --build`, we get a directory `...\build\bin\Release` that contains `Qt5Widgets.dll ` but not `Qt5Network.dll`.

What may be going wrong? How to debug?

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [January 7, 2020, 4:54pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/2 "2020-01-07T16:54:12Z")

</div>

First off, try changing the variable references to imported targets to ensure you’re not getting empty variables:

```cmake
target_link_libraries(mylib
    PRIVATE
    Qt5::Network
    Qt5::Gui
    Qt5::Widgets
    Qt5::Core
    )

```

If any of those targets don’t exist, you will get an error. If it succeeds, see if `Qt5Network.dll` is still missing.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [January 7, 2020, 5:02pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/3 "2020-01-07T17:02:08Z")

</div>

Syntax change made, problem persists: `Qt5Network.dll` still missing in `bin\Release`.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [January 7, 2020, 6:44pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/4 "2020-01-07T18:44:48Z")

</div>

I compared the files `Qt5Network/Qt5NetworkConfig.cmake` and `Qt5Widgets/Qt5WidgetsConfig.cmake`. Besides the trivial substitution “Network” -\> “Widgets” and a few references to functions from the respective libraries, there is just one big difference: `Qt5WidgetsConfig.cmake` has the lines

```auto
include("${CMAKE_CURRENT_LIST_DIR}/Qt5WidgetsConfigExtras.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Qt5WidgetsMacros.cmake")

```

which have no equivalent in `Qt5NetworkConfig.cmake`. Is this intentional? If so, why? Could it nonetheless be the unintended cause of my DLL problem?

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [January 7, 2020, 6:50pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/5 "2020-01-07T18:50:07Z")

</div>

Doubt it. Both of those files are the Qt framework asking each component “I’ve exported all of your targets in CMake. Do you have anything else to put into CMake?” It seems that for `Qt5Widgets` the answer is “yes”, but for `Qt5Network` the answer is “no”. But `Qt5Network` should still have the imported target.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [January 7, 2020, 9:46pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/6 "2020-01-07T21:46:23Z")

</div>

Kyle, I’m still puzzled by your latest response. Sounds really close to the decisive point, but too arcane for me to follow. Could you possibly elaborate a bit?

Also, I am no longer sure whether the anomaly is the absence of `Qt5Network`, or rather the presence of the three other libraries. Would CMake by default copy any DLL dependence to `CMAKE_RUNTIME_OUTPUT_DIRECTORY`?

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [January 7, 2020, 9:54pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/7 "2020-01-07T21:54:44Z")

</div>

Some of the modules in Qt export extra CMake macros, configuration variables, etc. These have to be placed in `Qt5<module>ConfigExtras.cmake` and `Qt5<module>Macros.cmake`. However, not all of them do, and the ones that don’t, don’t get these files included in their `Qt5<module>Config.cmake`. That’s why you’re seeing that diff, and I don’t think it has anything to do with why `Qt5Network` isn’t getting copied in.

Here’s a shot in the dark: try moving `Qt5::Network` to the end of the list and see if you get the same result.

---

<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: [January 7, 2020, 10:06pm UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/8 "2020-01-07T22:06:24Z")

</div>

I’m more curious why `Qt5Widgets.dll` is being copied into the `CMAKE_RUNTIME_OUTPUT_DIRECTORY`. What is causing that to be done?

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [January 8, 2020, 11:33am UTC](https://discourse.cmake.org/t/qt5-component-library-not-copied-to-cmake-runtime-output-directory/461/9 "2020-01-08T11:33:46Z")

</div>

Indeed, the strange behavior is the copying of Qt5Widgets.dll etc.

By bisectioning my real application, I found out that it is caused not by the code communicated in my original post, but by an obscure PackIFW script that calls windeployqt.exe.

Sorry.
