WinDeployqt 不会为调试应用程序部署 Qwindowsd.dll

windeployqt doesn't deploy qwindowsd.dll for a debug application

本文关键字:部署 Qwindowsd dll 应用程序 调试 WinDeployqt      更新时间:2023-10-16

>我正在尝试使用windeployqt.exe(Qt 5.13.2(为CMake 3.16生成的调试应用程序部署dll。除平台插件 dll 外,所有 dll 都已正确部署,它部署qwindows.dll而不是qwindowsd.dll,并在我尝试运行可执行文件时导致以下错误:

此应用程序无法启动,因为无法初始化Qt平台插件。

到目前为止,我已经尝试过:

  • windeployqt命令行上指定--debug。失败了,因为找不到Qt5Coredd.dll(注意双 d(。
  • 验证是否未设置与Qt插件相关的环境变量。
  • 已检查PATH以确保它不包含任何具有platforms目录的文件夹。

如果我手动复制qwindowsd.dll,一切正常。但是我真的很想弄清楚我做错了什么windeployqt.

这显然是一个已知的问题,Qt在修复时拖了后腿,但我在CMake中找到了解决方法 - 这适用于Ninja生成器/Visual Studio的内置CMake支持以及常规的Visual Studio解决方案生成器

# 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()

我在使用 Conan 2.0 和 CMakeToolchain 和CMakeDeps生成器时遇到了这个问题。我正在运行conan install .. --output-folder=. -b missing -s build_type=Debug并使用CMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake.使用默认的 Conan 配置文件,这将在调试模式下创建一个可执行文件,该可执行文件发布VC 运行时链接。

要解决此问题,您可以为指定compiler.runtime_type=Debug的调试版本创建新的配置文件,也可以使用-s compiler.runtime_type=Debug运行conan install