Issues running an app using a custom library with Qt 6.9.1
-
Hi everyone,
I'm currently developing a project on Windows 11 using Qt 6.9.1 (MSVC 2022) and CMake.
The setup consists of two parts:- MyLib: a library that defines some custom widgets, which also use QtWebEngine components (e.g. QWebEngineView, QWebChannel, …).
- MyExec: a GUI application (for Windows) that uses both Qt libraries and the custom widgets from MyLib.
I successfully build and install MyLib using CMake, and I get the .lib and .dll files without any issues.
However, I'm facing several problems when building and running MyExec:
- The only configuration that runs (without immediate startup errors) is when MyLib is built in Release and linked with MyExec also in Release. But in this case, the application crashes as soon as I open a panel that uses one of the custom widgets from MyLib.
- If I build MyLib and MyExec in Debug, the build succeeds, but when I run windeployqt.exe to deploy the required Qt libraries into the build folder, I get the following error:
[build] Checking C:/Qt/6.9.1/msvc2022_64/resources/icudtl.dat, C:/path/to/git/MyExec/build/Debug/resources/icudtl.dat [build] icudtl.dat is up to date. [build] Checking C:/Qt/6.9.1/msvc2022_64/resources/qtwebengine_devtools_resources.debug.pak, C:/path/to/git/MyExec/build/Debug/resources/qtwebengine_devtools_resources.debug.pak [build] C:\Qt\6.9.1\msvc2022_64\resources\qtwebengine_devtools_resources.debug.pak does not exist. [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: The command "setlocal [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -E echo "Copying MyLib" [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -E copy_if_different C:\path\to\git\MyLib/install/bin/MyLibd.dll C:/path/to/git/MyExec/build/Debug [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -E echo "MyLib copied successfully" [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmErrorLevel [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: exit /b %1 [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmDone [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: setlocal [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -E echo "Running windeployqt to deploy Qt dependencies" [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -E env QT_PLUGIN_PATH=C:\Qt\6.9.1\msvc2022_64/plugins C:\Qt\6.9.1\msvc2022_64/bin/windeployqt.exe --no-translations --verbose 2 --debug C:/path/to/git/MyExec/build/Debug [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -E echo "windeployqt completed successfully" [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmErrorLevel [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: exit /b %1 [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :cmDone [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd [C:\path\to\git\MyExec\build\MyExec.vcxproj] [build] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :VCEnd" exited with code 1. [C:\path\to\git\MyExec\build\MyExec.vcxproj] [proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/path/to/git/MyExec/build --config Debug --target MyExec -j 28 -- exited with code: 1 [driver] Build completed: 00:00:14.862 [build] Build finished with exit code 1
I use CMake via the VS Code extension, the command it launches automatically is:
[main] Building folder: c:/path/to/git/MyExec/build [build] Starting build [proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/path/to/git/MyExec/build --config Debug --target MyExec -j 28 -- [build] MSBuild version 17.13.9+e0f243f1e for .NET Framework
In the CMakeLists.txt there are these lines of code:
if (WIN32) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Copying MyLib" COMMAND ${CMAKE_COMMAND} -E copy_if_different $<$<CONFIG:Debug>:${MyLib_DLL_DEBUG}>$<$<CONFIG:Release>:${MyLib_DLL_RELEASE}> $<TARGET_FILE_DIR:${PROJECT_NAME}> COMMAND ${CMAKE_COMMAND} -E echo "MyLib copied successfully" ) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Running windeployqt to deploy Qt dependencies" COMMAND ${CMAKE_COMMAND} -E env QT_PLUGIN_PATH=$ENV{QT6DIR}/plugins $ENV{QT6DIR}/bin/windeployqt.exe --no-translations --verbose 2 $<$<CONFIG:Debug>:--debug>$<$<CONFIG:Release>:--release> $<TARGET_FILE_DIR:${PROJECT_NAME}> COMMAND ${CMAKE_COMMAND} -E echo "windeployqt completed successfully" ) endif()
The error seems related to the missing file qtwebengine_devtools_resources.debug.pak, but I was unable to find any reference about it, even using the Qt Maintenance Tool.
Any help would be appreciated :)
-
I've found a workaround and was able to make it go. I followd these steps:
- I forced the Qt libraries to be in Release mode, both in MyLib and in MyExec
- I forced the windeployqt to copy always Release configuration dependencies
- I forced the runtime library in MyLib and MyExec to be in release mode only
-
This is not a Qt problem but a general one with the msvc runtime - you must not mix different msvc runtimes (static, shared, debug, release)