我正在尝试使用windeployqt.exe
(Qt 5.13.2) 为 CMake 3.16 生成的调试应用程序部署 dll。除了部署的平台插件 dll 之外,所有 dll 均已正确部署qwindows.dll
代替qwindowsd.dll
当我尝试运行可执行文件时,会出现以下错误:
该应用程序无法启动,因为无法初始化 Qt 平台插件。
到目前为止,我已经尝试过:
- 指定
--debug
on the windeployqt
命令行。那失败了,因为Qt5Coredd.dll
找不到(注意双 d)。
- 验证是否未设置 Qt 插件相关的环境变量。
- Checked
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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)