# How to copy dll files to the binary folder

**URL:** https://discourse.cmake.org/t/how-to-copy-dll-files-to-the-binary-folder/5370
**Category:** Usage
**Created:** [April 5, 2022, 11:35am UTC](https://discourse.cmake.org/t/how-to-copy-dll-files-to-the-binary-folder/5370 "2022-04-05T11:35:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![JuliusCaesar](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@JuliusCaesar](https://discourse.cmake.org/u/JuliusCaesar)
#### Post date: [April 5, 2022, 11:35am UTC](https://discourse.cmake.org/t/how-to-copy-dll-files-to-the-binary-folder/5370/1 "2022-04-05T11:35:05Z")

</div>

Hey guys,  
in order to get QT to work properly I have to copy the QT dlls to the binary folder on windows.  
According to the docs ([https://cmake.org/cmake/help/latest/command/install.html#directory](https://cmake.org/cmake/help/latest/command/install.html#directory)) this should be easily done via  
`install(DIRECTORY "${QT_BASE_DIR}/bin/" DESTINATION ${CMAKE_CURRENT_BINARY_DIR} FILES_MATCHING PATTERN "*.dll")`

However no files are copied to my binary folder. Am I missing something? Is this not the purpose of the install() function?

thanks for your help 🙂

greets Julian

---

<div class="post-metadata">

### Author: ![imikejackson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/imikejackson/32/301_2.png) [@imikejackson](https://discourse.cmake.org/u/imikejackson)
#### Post date: [April 5, 2022, 12:41pm UTC](https://discourse.cmake.org/t/how-to-copy-dll-files-to-the-binary-folder/5370/2 "2022-04-05T12:41:01Z")

</div>

That command will not work for a build (unless you run the “INSTALL” command after every build). We used to copy all of the DLLs into the build directory but now we do this instead:

# -----------------------------------------------------------------------

# Configure Visual Studio runtime environment

# -----------------------------------------------------------------------

if(WIN32)  
set\_target\_properties(${PROJECT\_NAME} PROPERTIES  
VS\_DEBUGGER\_ENVIRONMENT “PATH=%PATH%;${VTK\_PREFIX\_PATH}/bin;${QT\_ROOT}/bin;${QT\_ROOT}/plugins/platforms”)  
endif()

---

<div class="post-metadata">

### Author: ![JuliusCaesar](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@JuliusCaesar](https://discourse.cmake.org/u/JuliusCaesar)
#### Post date: [April 5, 2022, 3:45pm UTC](https://discourse.cmake.org/t/how-to-copy-dll-files-to-the-binary-folder/5370/3 "2022-04-05T15:45:03Z")

</div>

thx for your answer.  
I put your suggestion directly beneath add\_executable()

```auto
 add_executable( ${APP_NAME} ${APP_SRC} )
 if(WIN32)
  set(QT_ROOT "C:/Qt/5.15.8/msvc2019_64")
  set_target_properties(${APP_NAME} PROPERTIES
  VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;${QT_ROOT}/bin;${QT_ROOT}/plugins/platforms")
endif()

```

but this results in Qt5xxx.dll not found errors.  
Am I using your snippet correctly?  
I’m running newest CMake in VS 2022 with MSVC17

---

<div class="post-metadata">

### Author: ![JuliusCaesar](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@JuliusCaesar](https://discourse.cmake.org/u/JuliusCaesar)
#### Post date: [April 6, 2022, 11:58am UTC](https://discourse.cmake.org/t/how-to-copy-dll-files-to-the-binary-folder/5370/4 "2022-04-06T11:58:00Z")

</div>

I did some digging. It does not seam to setting the property

```auto
VS_DEBUGGER_ENVIRONMENT 

```

has any effect

When I open the generated solution the debuger environment is still only set to path.

 ![grafik](https://discourse.cmake.org/uploads/default/original/2X/b/b4f8da450ae4a9f43c7fd7de31054ae20a831146.png)

When I manually insert the Qt paths in the solution everything works fine.

=\>so the question is why is this property not properly passed to the solution

---

<div class="post-metadata">

### Author: ![vre](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@vre](https://discourse.cmake.org/u/vre)
#### Post date: [April 6, 2022, 10:28pm UTC](https://discourse.cmake.org/t/how-to-copy-dll-files-to-the-binary-folder/5370/5 "2022-04-06T22:28:13Z")

</div>

You need to escape the path separators `;` as they are treated as list separators in CMake. Try to use `\\\;` or if that does not help try `\;`. As you are using a merge environment you only need to define the additional parts of the path, i.e. `set_target_properties(${APP_NAME} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=${QT_ROOT}/bin\\\;${QT_ROOT}/plugins/platforms")`
