# CPack missed dlls copied by windeployqt

**URL:** https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873
**Category:** Usage
**Tags:** os:windows, cpack:archive
**Created:** [April 11, 2023, 6:38am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873 "2023-04-11T06:38:37Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Joseph](https://discourse.cmake.org/user_avatar/discourse.cmake.org/joseph/32/3344_2.png) [@Joseph](https://discourse.cmake.org/u/Joseph)
#### Post date: [April 11, 2023, 6:38am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873/1 "2023-04-11T06:38:37Z")

</div>

In my Qt-based project, I deploy qt dlls by following steps:

1. Run my custom cmake script by install(SCRIPT
2. My cmake script runs `windeployqt` during installation, and the working directory is set to CMAKE\_INSTALL\_PREFIX so it can run correctly

This works fine when I install my project, but when I try to package my project as an archive by `cpack -G ZIP`, Qt deployed dlls are missing from the archive. It seems that only files installed with `install()` function can be packed. And another discovery is that, cpack runs my custom script **again** during packaging, but it takes no works, because the command is executed in CMAKE\_INSTALL\_PREFIX, but not where applications are staged.

How can I make qt deployed files exist in my package?

---

<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: [April 24, 2023, 4:58am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873/2 "2023-04-24T04:58:31Z")

</div>

@craig.scott ?

---

<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: [April 25, 2023, 6:48am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873/3 "2023-04-25T06:48:08Z")

</div>

Can’t offer much advice here without a minimal, complete project that demonstrates the problem.

---

<div class="post-metadata">

### Author: ![Joseph](https://discourse.cmake.org/user_avatar/discourse.cmake.org/joseph/32/3344_2.png) [@Joseph](https://discourse.cmake.org/u/Joseph)
#### Post date: [April 25, 2023, 7:25am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873/4 "2023-04-25T07:25:03Z")

</div>

I have written a minimalist example, consisting of 3 files in one directory:

## Source code

Files:

- CMakeLists.txt
- main.cpp
- deploy.cmake.in

And here’s all the code:

```cmake
# CMakeLists.txt:
cmake_minimum_required(VERSION 3.0.0)
project(example VERSION 0.1.0)

find_package(Qt6 6.2.4 COMPONENTS Widgets REQUIRED)

add_executable(example main.cpp)
target_link_libraries(example PRIVATE Qt6::Widgets)
set_target_properties(example PROPERTIES WIN32_EXECUTABLE true)

find_program(windeployqt_exe windeployqt REQUIRED)
configure_file(deploy.cmake.in ${CMAKE_BINARY_DIR}/deploy.cmake)

install(TARGETS example
    RUNTIME DESTINATION .)
install(SCRIPT ${CMAKE_BINARY_DIR}/deploy.cmake)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

```

```cmake
# deploy.cmake.in
message(WARNING Running windeployqt...)
execute_process(COMMAND "@windeployqt_exe@" example.exe
    WORKING_DIRECTORY "@CMAKE_INSTALL_PREFIX@")

```

```cpp
// main.cpp
#include <QApplication>
#include <QWidget>
#include <iostream>

int main(int argc, char **argv) {
  QApplication qapp(argc, argv);
  QWidget wind;
  wind.show();
  return qapp.exec();
}

```

## Commands from config to pack

I configure and build it with:

```cmd
cmake -S D:/Git/example -B D:/Git/build-example-win -G Ninja -DCMAKE_PREFIX_PATH=D:/ProgramFiles/Qt/libQt/Qt6.4.0-gcc12-shared -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/g++.exe -DCMAKE_INSTALL_PREFIX:PATH=D:/Git/build-example-win/install

cmake --build D:/Git/build-example-win

```

And install in the build directory with:

```cmd
cmake --install .

```

And run cpack in the build directory with:

```cmd
cpack -G ZIP

```

## Outputs

The output during configuration is:

```plaintext
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- Configuring done (1.5s)
-- Generating done (0.0s)
-- Build files have been written to: D:/Git/build-example-win

```

The output during build is:

```plaintext
[2/2] Linking CXX executable example.exe

```

The output during installation is:

```plaintext
-- Install configuration: "Debug"
-- Installing: D:/Git/build-example-win/install/./example.exe
CMake Warning at deploy.cmake:1 (message):
  Runningwindeployqt...
Call Stack (most recent call first):
  cmake_install.cmake:51 (include)

D:\Git\build-example-win\install\example.exe 64 bit, release executable
Direct dependencies: Qt6Core Qt6Widgets
All dependencies : Qt6Core Qt6Gui Qt6Widgets
To be deployed : Qt6Core Qt6Gui Qt6Widgets
Warning: Cannot find GCC installation directory. g++.exe must be in the path.
Updating Qt6Core.dll.
Updating Qt6Gui.dll.
Updating Qt6Widgets.dll.
Updating D3Dcompiler_47.dll.
Creating directory D:/Git/build-example-win/install/imageformats.
Updating qgif.dll.
Updating qico.dll.
Updating qjpeg.dll.
Creating directory D:/Git/build-example-win/install/platforms.
Updating qwindows.dll.
Creating directory D:/Git/build-example-win/install/styles.
Updating qwindowsvistastyle.dll.
Creating D:\Git\build-example-win\install\translations...
Warning: Could not find any translations in D:\ProgramFiles\Qt\libQt\Qt6.4.0-gcc12-shared\translations (developer build?)
.

```

The output during packaging is:

```plaintext
CPack: Create package using ZIP
CPack: Install projects
CPack: - Install project: example []
CMake Warning at D:/Git/build-example-win/deploy.cmake:1 (message):
  Runningwindeployqt...
Call Stack (most recent call first):
  D:/Git/build-example-win/cmake_install.cmake:51 (include)

D:\Git\build-example-win\install\example.exe 64 bit, release executable
Direct dependencies: Qt6Core Qt6Widgets
All dependencies : Qt6Core Qt6Gui Qt6Widgets
To be deployed : Qt6Core Qt6Gui Qt6Widgets
Warning: Cannot find GCC installation directory. g++.exe must be in the path.
Qt6Core.dll is up to date.
Qt6Gui.dll is up to date.
Qt6Widgets.dll is up to date.
D3Dcompiler_47.dll is up to date.
qgif.dll is up to date.
qico.dll is up to date.
qjpeg.dll is up to date.
qwindows.dll is up to date.
qwindowsvistastyle.dll is up to date.
Warning: Could not find any translations in D:\ProgramFiles\Qt\libQt\Qt6.4.0-gcc12-shared\translations (developer build?)
.CPack: Create package
CPack: - package: D:/Git/build-example-win/example-0.1.0-win64.zip generated.

```

## What really happen:

The zip pack is generated, but it contains only one executable: `example.exe`. All dlls deployed by `windeployqt` are missing from zip package.

## What I hope to happen:

I hope that all deployed files can be added in the zip archive.

---

<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: [April 25, 2023, 8:00am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873/8 "2023-04-25T08:00:36Z")

</div>

> [@Joseph](#):
>
> I can’t reply you! What happened?

Your replies were flagged as spam and needed manual review. I’ve marked them all as not spam. Please delete the messages we don’t need and just keep the most relevant one.

---

<div class="post-metadata">

### Author: ![Joseph](https://discourse.cmake.org/user_avatar/discourse.cmake.org/joseph/32/3344_2.png) [@Joseph](https://discourse.cmake.org/u/Joseph)
#### Post date: [April 25, 2023, 8:29am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873/10 "2023-04-25T08:29:47Z")

</div>

Thank you. I have deleted unrevelant messages now.

---

<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: [April 26, 2023, 8:58am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873/11 "2023-04-26T08:58:05Z")

</div>

You cannot set your `WORKING_DIRECTORY` in the `deploy.cmake` script to `"@CMAKE_INSTALL_PREFIX@"`. That will force it to try to use the configure-time install prefix as the working directory because that value is substituted from the variable’s value when CMake runs the configure step. I’m guessing you meant for that value to be the install prefix as used at install time. To do that, change this to `"${CMAKE_INSTALL_PREFIX}"` and add `@ONLY` to the end of your `configure_file()` call to prevent it from be substituted.

---

<div class="post-metadata">

### Author: ![Joseph](https://discourse.cmake.org/user_avatar/discourse.cmake.org/joseph/32/3344_2.png) [@Joseph](https://discourse.cmake.org/u/Joseph)
#### Post date: [April 26, 2023, 11:10am UTC](https://discourse.cmake.org/t/cpack-missed-dlls-copied-by-windeployqt/7873/13 "2023-04-26T11:10:35Z")

</div>

Thanks very much, it works!
