From 94279afff86252b8b777450a56990fa33ffbb0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Keller?= Date: Tue, 11 Apr 2023 16:38:49 +0200 Subject: [PATCH] Windeployqt: change MinGW dll's import location The MinGW runtimes were imported through the PATH, which creates mismatches with the expected libraries that are installed directly through Qt. Check if those can be used instead, and issue a warning (and default to PATH) if not. Fixes: QTBUG-112448 Pick-to: 6.5 Change-Id: I061baabb6d6188bd0817b68c39a5d9f04ff391b5 Reviewed-by: Oliver Wolff --- src/tools/windeployqt/main.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/tools/windeployqt/main.cpp b/src/tools/windeployqt/main.cpp index bec0291ae2..093e21e36c 100644 --- a/src/tools/windeployqt/main.cpp +++ b/src/tools/windeployqt/main.cpp @@ -1084,25 +1084,30 @@ static QString vcRedistDir() return QString(); } -static QStringList compilerRunTimeLibs(Platform platform, bool isDebug, unsigned short machineArch) +static QStringList compilerRunTimeLibs(const QString &qtBinDir, Platform platform, bool isDebug, unsigned short machineArch) { QStringList result; switch (platform) { - case WindowsDesktopMinGW: { // MinGW: Add runtime libraries + case WindowsDesktopMinGW: { // MinGW: Add runtime libraries. Check first for the Qt binary directory, and default to path if nothing is found. static const char *minGwRuntimes[] = {"*gcc_", "*stdc++", "*winpthread"}; - const QString gcc = findInPath(QStringLiteral("g++.exe")); - if (gcc.isEmpty()) { - std::wcerr << "Warning: Cannot find GCC installation directory. g++.exe must be in the path.\n"; - break; - } - const QString binPath = QFileInfo(gcc).absolutePath(); QStringList filters; const QString suffix = u'*' + sharedLibrarySuffix(platform); for (auto minGwRuntime : minGwRuntimes) filters.append(QLatin1StringView(minGwRuntime) + suffix); - const QFileInfoList &dlls = QDir(binPath).entryInfoList(filters, QDir::Files); + + QFileInfoList dlls = QDir(qtBinDir).entryInfoList(filters, QDir::Files); + if (dlls.isEmpty()) { + std::wcerr << "Warning: Runtime libraries not found in Qt binary folder, defaulting to path\n"; + const QString gcc = findInPath(QStringLiteral("g++.exe")); + if (gcc.isEmpty()) { + std::wcerr << "Warning: Cannot find GCC installation directory. g++.exe must be in the path.\n"; + break; + } + const QString binPath = QFileInfo(gcc).absolutePath(); + dlls = QDir(binPath).entryInfoList(filters, QDir::Files); + } for (const QFileInfo &dllFi : dlls) - result.append(dllFi.absoluteFilePath()); + result.append(dllFi.absoluteFilePath()); } break; #ifdef Q_OS_WIN @@ -1435,7 +1440,7 @@ static DeployResult deploy(const Options &options, const QMap options.directory : options.libraryDirectory; QStringList libraries = deployedQtLibraries; if (options.compilerRunTime) - libraries.append(compilerRunTimeLibs(options.platform, result.isDebug, machineArch)); + libraries.append(compilerRunTimeLibs(qtBinDir, options.platform, result.isDebug, machineArch)); for (const QString &qtLib : std::as_const(libraries)) { if (!updateLibrary(qtLib, targetPath, options, errorMessage)) return result;