DicomViewer24 修复编译bug(window test 失败)

背景

上一篇mpr的推到GitHub上,本来以为不会有啥问题,结果ci打包的失败了。这一篇是解决问题的。

正文

git ci 失败

从流程来看,是Windows build就失败了。

追踪日志,结论是生成test的超时了。。但是如果直接补超时时间不一定能解决问题,还是得在Windows下编译才能知道是不是超时导致的

window cmake 插件编译

因为上面的bug是在Windows下编译出现的,先解决Windows下编译的。 之前因为都是wsl下,然后Windows下只用了脚本编译,这一次使用了vscode的插件cmake编译

一开始尝试环境变量,结果没生效,可能是到vscode的cmake这一次继承的环境变量有问题(用的系统变量设置的,重启也无效,从控制台输出环境变量是正常),最终直接在CMakePresets.json写死了,如下所示

bash 复制代码
   {
      "name": "win-vcpkg-debug",
      "displayName": "Windows vcpkg",
      "description": "Debug build on Windows (x64-windows)",
      "binaryDir": "${sourceDir}/build",
      "generator": "",
      "toolchainFile": "D:/vcpkg/scripts/buildsystems/vcpkg.cmake",
      "environment": {
        "VCPKG_ROOT": "D:/vcpkg"
      },
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug",
        "CMAKE_CXX_FLAGS": "",
        "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/triplets",
        "VCPKG_TARGET_TRIPLET": "x64-windows",
        "AUTO_TESTING": "ON",
        "DEPLOY_QT_PLUGINS": "ON"
      },
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      }
    },

Windows 编译触发

编译过程中会跳出如下窗口

有这弹框,基本上补超时时间是没用了

执行单个的测试来重现

bash 复制代码
D:/xcyxiner/DicomViewer/build/Debug/ViewMode_test.exe --gtest_list_tests

从结果来看,设置超时应该是没用了,缺少类库

给AI输入

复制代码
 从结果来看,是因为你开了无头模式,但是在Windows下,没有找到对应的插件导致的

AI 给的修复意见

拷贝插件并测试

修复过程 CMakeLists.txt 补拷贝方法,生成测试文件前调用

bash 复制代码
# ---- Windows: 自动部署 Qt 插件 ----
# 用整目录拷贝代替逐个 DLL 点名:platforms 里的 offscreen/minimal 等
# 无头插件是测试 (gtest_discover_tests) 在构建期就要加载的,漏拷会导致
# 发现阶段超时;imageformats/styles/generic 供运行时按需加载。
option(DEPLOY_QT_PLUGINS "Auto-copy Qt plugins after build" OFF)
if(WIN32 AND MSVC AND DEPLOY_QT_PLUGINS)
    set(_qt_vcpkg_root
        "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}")
    # Debug 走 debug 树(DLL 带 d 后缀),其余配置走 release 树
    set(_qt_plugin_tree
        "$<IF:$<CONFIG:Debug>,debug/,>")

    function(_deploy_qt_plugins target)
        foreach(_plugin_cat platforms imageformats styles generic)
            add_custom_command(TARGET ${target} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy_directory
                    "${_qt_vcpkg_root}/${_qt_plugin_tree}Qt6/plugins/${_plugin_cat}"
                    "$<TARGET_FILE_DIR:${target}>/${_plugin_cat}"
                COMMENT "Deploying Qt ${_plugin_cat} plugins ($<CONFIG>)"
            )
        endforeach()
    endfunction()

    _deploy_qt_plugins(DicomViewer_exe)
endif()

重新编译并跑所有的测试

git commit

github.com/xcyxiner/Di...

相关推荐
linux_cfan1 小时前
videojs v10 源代码系列解读:34 · `createComposition`:类型安全的冲突检测
前端·安全
utmhikari2 小时前
【AI原生】借助AI之力优化个人博客前端样式
前端·css·hexo·next·个人博客·ai-native·vibe coding
小凯在掘金3 小时前
为什么箭头函数不能作为构造函数?
前端·javascript
JustHappy4 小时前
「vConsole MCP🛠️」我让 AI 直接看见任何 H5 的日志和请求帮你 debug
前端·javascript·程序员
codeGoogle4 小时前
Vue3 UIKit 实战:把聊天、会话、主题和移动端适配全部封装好
前端
大龄秃头程序员5 小时前
iOS Method Swizzling 的工程化实践:如何处理多重交换与第三方冲突
前端
liangshanbo12155 小时前
Webpack 文件指纹面试题整理
前端·webpack·node.js
xieter5 小时前
【技术精选】Node.js 核心事件循环机制与异步 I/O 深度剖析 (2026-10-02)
前端·javascript