microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.8k stars 6.3k forks source link

[qtimageformats] 6.5.3#0 can't load jpeg and webp #40721

Open Hlongyu opened 2 weeks ago

Hlongyu commented 2 weeks ago

Describe the bug QImageReader::supportedImageFormats() not include jpeg and webp

Environment

To Reproduce Steps to reproduce the behavior:

  1. cmake -S . -B build --preset windows-x64-Release
  2. Run exe

vcpkg.json

{
    "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
    "dependencies": [
        {
            "name": "qtbase",
            "version>=": "6.5.3#0",
            "platform": "windows"
        },
        {
            "name": "qtimageformats",
            "default-features": false,
            "version>=": "6.5.3#0",
            "features": [
                "webp"
            ],
            "platform": "windows"
        }
    ],
    "builtin-baseline": "02745e0f4749d1f51d2025824209408f5a6c3614",
    "overrides": [
        {
            "name": "qtbase",
            "version": "6.5.3#0"
        },
        {
            "name": "qtimageformats",
            "version": "6.5.3#0"
        }
    ]
}

main.cpp

#include <QApplication>
#include <QImageReader>
#include <iostream>
int main(int argc, char **argv) {
  QApplication app(argc, argv);
  auto support = QImageReader::supportedImageFormats();
  for (auto &i : support) {
    qDebug() << i;
  }
  app.exec();
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.9)

project(QtImageFormatTest VERSION 0.1 LANGUAGES CXX)

find_package(Qt6 CONFIG REQUIRED)
find_package(Qt6Core CONFIG REQUIRED)
find_package(Qt6Widgets CONFIG REQUIRED)
find_package(Qt6Gui CONFIG REQUIRED)

add_executable(QtImageFormatTest main.cpp)

target_link_libraries(QtImageFormatTest PRIVATE Qt6::Widgets Qt6::Core Qt6::Gui)

if(WIN32)
    if (CMAKE_BUILD_TYPE STREQUAL "Debug")
        find_program(TOOL_WINDEPLOYQT NAMES windeployqt.debug.bat)
    else()
        find_program(TOOL_WINDEPLOYQT NAMES windeployqt)
    endif()

add_custom_command(TARGET QtImageFormatTest POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E echo "Run windeployqt"

    COMMAND ${TOOL_WINDEPLOYQT}
            $<TARGET_FILE:QtImageFormatTest>
    COMMAND ${CMAKE_COMMAND} -E echo "end windeployqt"
)
endif()

CMakePresets.json

{
    "version": 5,
    "configurePresets": [
        {
            "name": "windows-x64-Debug",
            "generator": "Ninja",
            "binaryDir": "${sourceDir}/out/build/${presetName}",
            "architecture": {
                "value": "x64",
                "strategy": "external"
            },
            "toolset": {
                "value": "host=x64",
                "strategy": "external"
            },
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug",
                "CMAKE_CXX_COMPILER": "cl.exe",
                "CMAKE_C_COMPILER": "cl.exe",
                "CMAKE_TOOLCHAIN_FILE": "D:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake",
                "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
            }
        },
        {
            "name": "windows-x64-Release",
            "generator": "Ninja",
            "binaryDir": "${sourceDir}/out/build/${presetName}",
            "architecture": {
                "value": "x64",
                "strategy": "external"
            },
            "toolset": {
                "value": "host=x64",
                "strategy": "external"
            },
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "RelWithDebInfo",
                "CMAKE_CXX_COMPILER": "cl.exe",
                "CMAKE_C_COMPILER": "cl.exe",
                "CMAKE_TOOLCHAIN_FILE": "D:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake",
                "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
            }
        }
    ]
}

Expected behavior Support jpeg and webp.

Failure logs

Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qgifd.dll'. Symbols loaded.
Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qicnsd.dll'. Symbols loaded.
Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qicod.dll'. Symbols loaded.
Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qjpegd.dll'. Symbols loaded.
Unloaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qjpegd.dll'.
Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qtgad.dll'. Symbols loaded.
Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qwbmpd.dll'. Symbols loaded.
Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qwebpd.dll'. Symbols loaded.
Unloaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qwebpd.dll'.
"bmp"
"cur"
"gif"
"icns"
"ico"
"pbm"
"pgm"
"png"
"ppm"
"tga"
"wbmp"
"xbm"
"xpm"
dg0yt commented 2 weeks ago

Check that the DLLs for jpeg and webp libs are deployed and found, too. When it comes to plugins, deployment of transitive runtime dependencies is ... tricky.

Hlongyu commented 2 weeks ago

Check that the DLLs for jpeg and webp libs are deployed and found, too.

Directory: D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats

Mode LastWriteTime Length Name


-a--- 2024/8/30 10:39 130560 qgifd.dll -a--- 2024/8/30 10:49 157696 qicnsd.dll -a--- 2024/8/30 10:39 137216 qicod.dll -a--- 2024/8/30 10:39 162816 qjpegd.dll -a--- 2024/8/30 10:49 97280 qtgad.dll -a--- 2024/8/30 10:49 93184 qwbmpd.dll -a--- 2024/8/30 10:49 105984 qwebpd.dll

dg0yt commented 2 weeks ago

These are the Qt plugins. Some plugins need DLLs with the actual implementation.

Hlongyu commented 1 week ago

When i debug step by step. I found it will call LoadLibrary() for qjpegd.dll.

hnd = LoadLibrary(reinterpret_cast<const wchar_t*>(QDir::toNativeSeparators(attempt).utf16()));

Loaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qjpegd.dll'. Symbols loaded.
Unloaded 'D:\dev\qt-bug-report\out\build\windows-x64-Debug\imageformats\qjpegd.dll'. 
dg0yt commented 1 week ago

That's just the same information as in the initial post: It fails to load the plugin. But the plugin is there. I already suggest that it might be failing because the plugin fails find runtime dependencies (DLLs), here the jpeg DLL from port libjpeg-turbo.