How to copy Qt runtime DLLs to project output

后端 未结 4 1379
生来不讨喜
生来不讨喜 2021-02-01 15:46

I have a simple project created in Qt Creator (installed using Qt SDK 1.1.4). It runs just fine from within Qt Creator, but if I then browse to the output directory in Windows

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 16:16

    Copy Dependencies with windeployqt

    # Deployment - Automatically Detect and Copy Dependencies to Build Folder
    
    TARGET_CUSTOM_EXT = .exe
    DEPLOY_COMMAND = windeployqt
    
    DEPLOY_OPTIONS = "--no-svg --no-system-d3d-compiler --no-opengl --no-angle --no-opengl-sw"
    
    CONFIG( debug, debug|release ) {
        # debug
        DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT}))
        DEPLOY_OPTIONS += "--debug"
    } else {
        # release
        DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT}))
        DEPLOY_OPTIONS += "--release"
    }
    
    # Uncomment the following line to help debug the deploy command when running qmake
    #message($${DEPLOY_COMMAND} $${DEPLOY_OPTIONS} $${DEPLOY_TARGET})
    
    QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_OPTIONS} $${DEPLOY_TARGET}
    

    or Copy dependencies manually

    # Deployment - Copy Dependencies to Build Folder
    
    dlls.path  =  $${DESTDIR}
    dlls.files += $$[QT_INSTALL_BINS]/icudt51.dll
    dlls.files += $$[QT_INSTALL_BINS]/icuin51.dll
    dlls.files += $$[QT_INSTALL_BINS]/icuuc51.dll
    dlls.files += $$[QT_INSTALL_BINS]/libgcc_s_dw2-1.dll
    dlls.files += $$[QT_INSTALL_BINS]/libstdc++-6.dll
    dlls.files += $$[QT_INSTALL_BINS]/libwinpthread-1.dll
    dlls.files += $$[QT_INSTALL_BINS]/Qt5Core.dll
    dlls.files += $$[QT_INSTALL_BINS]/Qt5Network.dll
    dlls.files += $$[QT_INSTALL_BINS]/Qt5Gui.dll
    dlls.files += $$[QT_INSTALL_BINS]/Qt5Widgets.dll
    dllA.path   += $${DESTDIR}/platforms
    dllA.files  += $$[QT_INSTALL_PLUGINS]/platforms/qwindows.dll
    dllB.path   += $${DESTDIR}/plugins/imageformats/
    dllB.files  += $$[QT_INSTALL_PLUGINS]/imageformats/qico.dll
    dllB.files  += $$[QT_INSTALL_PLUGINS]/imageformats/qwbmp.dll
    INSTALLS   += dlls dllA dllB
    

    Referencing: http://doc.qt.io/qt-5/qmake-variable-reference.html#deployment


    In case you need to identify prerequisites / dependencies cross-platform, please take a look at CMake's getPrerequisites(). It uses dumpbin, objbin, ldd, otool for the identification of dependencies.

    Referencing: https://cmake.org/cmake/help/v3.0/module/GetPrerequisites.html

提交回复
热议问题