You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下Qt多进程源码编译报错:文件被其他进程占用

Windows下Qt源码编译多进程随机文件占用错误的解决求助

我在Windows系统下从源码编译Qt,以下是最小复现的批处理脚本:

setlocal

@echo off

set DOWNLOAD_URL=https://qt-mirror.dannhauer.de/official_releases/qt/5.12/5.12.12/single/qt-everywhere-src-5.12.12.zip

For %%A in ("%DOWNLOAD_URL%") do (
    set FILENAME=%%~nxA
)

set WORK_DIR=%~dp0\qt
set SRC_DIR=%WORK_DIR%\src
set BUILD_DIR=%WORK_DIR%\build
set OUTPUT_DIR=%WORK_DIR%\out

rmdir /S /Q "%BUILD_DIR%"
rmdir /S /Q "%OUTPUT_DIR%"
mkdir "%BUILD_DIR%"
mkdir "%OUTPUT_DIR%"

if not exist "%WORK_DIR%\%FILENAME%" (
    curl -fL "%DOWNLOAD_URL%" --output "%WORK_DIR%\%FILENAME%"
    rmdir /S /Q %SRC_DIR%
)

if not exist "%SRC_DIR%" (
    mkdir %SRC_DIR%
    tar -vxf "%WORK_DIR%\%FILENAME%" -C %SRC_DIR% --strip-components 1
)

cd "%BUILD_DIR%"
call %SRC_DIR%/configure.bat ^
                -prefix %OUTPUT_DIR% ^
                -debug-and-release ^
                -opensource ^
                -confirm-license ^
                -make libs ^
                -nomake examples ^
                -nomake tests ^
                -qt-freetype ^
                -qt-harfbuzz ^
                -qt-pcre ^
                -qt-zlib ^
                -qt-libjpeg ^
                -qt-libpng ^
                -plugin-sql-sqlite ^
                -no-cups ^
                -no-evdev ^
                -no-glib ^
                -no-icu ^
                -no-opengl ^
                -no-xcb ^
                -no-xcb-xlib ^
                -no-xkbcommon ^
                -skip qt3d ^
                -skip qtandroidextras ^
                -skip qtcanvas3d ^
                -skip qtcharts ^
                -skip qtconnectivity ^
                -skip qtdatavis3d ^
                -skip qtdeclarative ^
                -skip qtdoc ^
                -skip qtgamepad ^
                -skip qtgraphicaleffects ^
                -skip qtimageformats ^
                -skip qtlocation ^
                -skip qtmacextras ^
                -skip qtmultimedia ^
                -skip qtpurchasing ^
                -skip qtquickcontrols ^
                -skip qtquickcontrols2 ^
                -skip qtscript ^
                -skip qtscxml ^
                -skip qtsensors ^
                -skip qtserialbus ^
                -skip qtserialport ^
                -skip qtspeech ^
                -skip qtsvg ^
                -skip qttranslations ^
                -skip qtvirtualkeyboard ^
                -skip qtwayland ^
                -skip qtwebchannel ^
                -skip qtwebengine ^
                -skip qtwebsockets ^
                -skip qtwebview ^
                -skip qtwinextras ^
                -skip qtx11extras ^
                -skip qtxmlpatterns

if %ERRORLEVEL% neq 0 (
    echo.&echo Configuration failed!
    exit /b 1
)

jom

if %ERRORLEVEL% neq 0 (
    echo.&echo Build failed!
    exit /b 1
)

编译过程中会随机出现错误:The process cannot access the file because it is being used by another process.,错误位置不固定,不绑定特定文件。

我已尝试以下方案:

  • 替换-debug-and-release为仅-release
  • 用set CL=/MP && nmake替代jom
  • 添加-mp参数后调用nmake
  • 更换Qt版本(如Qt 5.15.2)
  • 恢复Windows 10 Pro 21H2 19044.1826虚拟机至早期快照

以上方案均无效,仅单进程编译(直接调用nmake,不加CL=/MP或-mp参数)可成功,但只能利用单个核心,效率极低。我查到已关闭的QTBUG-66059,但无法解决问题,恳请提供可行的解决办法!

内容的提问来源于stack exchange,提问作者JenyaKh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 08:06:50