5

I'm trying to use windeployqt.exe (Qt 5.13.2) to deploy dlls for a debug application generated by CMake 3.16. All the dlls are deployed correctly except for the platform plugin dll, which deploys qwindows.dll instead of qwindowsd.dll and results in the following error when I try to run the executable:

This application failed to start because no Qt platform plugin could be initialized.

So far, I've tried:

  • Specifying --debug on the windeployqt command line. That failed because Qt5Coredd.dll could not be found (note the double d's).
  • Verifying that no Qt plugin related environment variables are set.
  • Checked PATH to make sure it doesn't contain any folder with a platforms directory.

If I copy qwindowsd.dll manually, everything works fine. However I'd really like to figure out what I'm doing wrong with windeployqt.

Nicolas Holthaus
  • 7,763
  • 4
  • 42
  • 97
  • If you add verbose flag do you get any additional information? – deW1 Jan 20 '20 at 18:01
  • @deW1 with level 2 enabled I could see that it was looking for a mix of release and debug libraries, but couldn't tell why – Nicolas Holthaus Jan 20 '20 at 18:02
  • Does it work when you create a new default Widgets Application -> Select CMake -> build -> run windeployqt TestWidgets.exe (for example). I've had 5.13.1 laying around works fine there. – deW1 Jan 20 '20 at 18:12
  • 1
    I’ve also noticed issues like this, all deployed plugins were in release mode. I think deploying debug builds isn’t really supported (the use cases are limited I think because there are legal restrictions to distributing the MSVC debug runtimes IIRC). Worth creating a minimal example and a bug report, I think. – Frank Osterfeld Jan 21 '20 at 08:39

2 Answers2

2

This is apparently a known problem that Qt have dragged their heels on fixing, but I figured out a workaround in CMake - this works for both the Ninja generator/Visual Studio's built in CMake support as well as the regular Visual Studio solution generator

# Split windeployqt into 2 parts to fix issue with deploying debug plugins
add_custom_command(TARGET MyApp POST_BUILD
    COMMAND ${QT_PATH}/bin/windeployqt --compiler-runtime --no-plugins ${MY_APP_EXE})
if (CMAKE_GENERATOR STREQUAL "Ninja")
    # Ninja is a single-config generator so we can use CMAKE_BUILD_TYPE to generate different commands
    if (CMAKE_BUILD_TYPE STREQUAL "Debug")
        add_custom_command(TARGET MyApp POST_BUILD
            COMMAND ${QT_PATH}/bin/windeployqt --debug --no-compiler-runtime --no-translations --no-libraries ${MY_APP_EXE})
    else()
        add_custom_command(TARGET MyApp POST_BUILD
            COMMAND ${QT_PATH}/bin/windeployqt --release --no-compiler-runtime --no-translations --no-libraries ${MY_APP_EXE})
    endif()
else()
    # if in MSVC we have to check the configuration at runtime instead of generating different commands
    add_custom_command(TARGET MyApp POST_BUILD
        COMMAND cmd.exe /c if "$(Configuration)" == "Debug" ${QT_PATH}/bin/windeployqt --debug --no-compiler-runtime --no-translations --no-libraries ${MY_APP_EXE})
    add_custom_command(TARGET MyApp POST_BUILD
        COMMAND cmd.exe /c if not "$(Configuration)" == "Debug" ${QT_PATH}/bin/windeployqt --release --no-compiler-runtime --no-translations --no-libraries ${MY_APP_EXE})
endif()
rdowell
  • 729
  • 4
  • 15
0

I ran into this problem myself when using Conan 2.0 and the CMakeToolchain and CMakeDeps generators. I was running conan install .. --output-folder=. -b missing -s build_type=Debug and used CMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake. With the default Conan profile, this will create an executable in debug mode that is linked against the release VC runtime.

To fix this, you can either create a new profile for debug builds where you specify compiler.runtime_type=Debug or run conan install with -s compiler.runtime_type=Debug.

Nerix
  • 131
  • 1
  • 3