# RUNTIME\_DEPENDENCIES cannot find dll

**URL:** https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782
**Category:** Code
**Created:** [July 19, 2021, 4:12pm UTC](https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782 "2021-07-19T16:12:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [July 19, 2021, 4:12pm UTC](https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782/1 "2021-07-19T16:12:35Z")

</div>

Hi,

I’m using RUNTIME\_DEPENDENCIES with CMake 3.21 as follow:

```auto
install(TARGETS MyApp
  RUNTIME_DEPENDENCIES
    PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
    POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
)

```

But it says "file Could not resolve file qt6core.dll`. What is going wrong here? MyApp is target linking to Qt6Core, so the library should be found (Qt6 is in my PATH on Windows). Why is it not found?

Note: This also happens when using the “old” code:

```auto
install(CODE "set(DEPENDENCY_PATHS \"${DEPENDENCY_PATHS}\")")
install(CODE [[
  file(GET_RUNTIME_DEPENDENCIES
    LIBRARIES "$<TARGET_FILE:BeansApp>"
    RESOLVED_DEPENDENCIES_VAR _r_deps
    UNRESOLVED_DEPENDENCIES_VAR _u_deps
    DIRECTORIES ${DEPENDENCY_PATHS}
    PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
    POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
  )
  foreach(_file ${_r_deps})
    file(INSTALL
      DESTINATION "${CMAKE_INSTALL_PREFIX}/bin"
      TYPE SHARED_LIBRARY
      FILES "${_file}"
    )
  endforeach()
  list(LENGTH _u_deps _u_length)
  if("${_u_length}" GREATER 0)
    message(WARNING "Unresolved dependencies detected!")
  endif()
]])

```

---

<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: [July 19, 2021, 5:10pm UTC](https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782/2 "2021-07-19T17:10:44Z")

</div>

You need to include the directory containing `qt6core.dll` in the `DIRECTORIES` argument.

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [July 19, 2021, 7:11pm UTC](https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782/3 "2021-07-19T19:11:36Z")

</div>

Why is this necessary? The QT Directory is on the PATH and actually found by find\_package. The qt6 target is then also linked to my target. So CMake really should have all information needed to figure this out. Either by searching the path or by just using the lib that it already found.

If I really have to specify DIRECTORIES, I don’t quite see the use of  
GET\_RUNTIME\_DEPENDENCIES. Then I could just as well list the libraries manually?

I’m not sure how I would set DIRECTORIES either. The Qt6 lib is in the PATH or specified via CMAKE\_PREFIX\_PATH. I have no idea where is actually is on different systems. My primary goal with RUNTIME\_DEPENDCIES was to automate this in a generic way without relying on hardcoded paths and such stuff.

---

<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: [July 19, 2021, 7:32pm UTC](https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782/4 "2021-07-19T19:32:01Z")

</div>

`DIRECTORIES` is more needed on Windows than on Linux and Mac because it has no equivalent to RPATH. Linux rarely needs `DIRECTORIES` (and warns you if it finds something in a `DIRECTORIES` argument), and on Mac it isn’t even used at all.

We deliberately made the decision to not consider the `PATH` variable in `file(GET_RUNTIME_DEPENDENCIES)`, because setting the `PATH` from outside the project could change the results of it. You can add `$<TARGET_DIR:qt6core>` to the `DIRECTORIES` argument, which should allow it to find it.

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [July 24, 2021, 8:45am UTC](https://discourse.cmake.org/t/runtime-dependencies-cannot-find-dll/3782/5 "2021-07-24T08:45:50Z")

</div>

I think I do understand why this is not happening automatically. As the command is evaluated at a different time, where target information is not available.

But I wonder why it’s not done at some other time. CMake knows in general my target and it dependencies and could set the DIRECTORIES Argument for instance automatically.
