Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Does QT 5.9.1 static (/MT) build broken?



  • Hi there.
    Also i try to build static version of QT 5.9.1 for msvc-2015 x86.

    configure -static -debug-and-release -prefix "c:\Qt\5.9.1\static" -platform win32-msvc2015 -qt-zlib -opensource -confirm-license -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -skip qt3d -skip qttools -opengl dynamic -make libs -nomake tools -skip qtdoc -skip qtwayland -skip qtwebview -skip qtwebengine -skip qtwebchannel -no-qml-debug -skip qtscript -no-icu -no-compile-examples -nomake examples -nomake tests
    

    Also i changed all /MD flags to /MT in file \Qt\5.9.1\Src\qtbase\mkspecs\common\msvc-desktop.conf

    Compilation was successful but when compiling my .exe i got a lot of linkage errors like

    Qt5Cored.lib(qregularexpression.obj) : error LNK2001: unresolved external symbol _pcre2_config_16
    Qt5Guid.lib(qpnghandler.obj) : error LNK2001: unresolved external symbol _png_write_chunk
    Qt5Widgetsd.lib(qwindowsxpstyle.obj) : error LNK2001: unresolved external symbol __imp__GetThemeEnumValue@20
    

    I also start full static build without -skip options

    Can somebody confirm that static bulds work properly?



  • Finally i build fully static app)
    But it contains a lot of windows dlls dependencies.

    Important things for static apps:

    1. All plugins disabled, so you need load it manually with "Q_IMPORT_PLUGIN"
      For example my app need 2 plugins:
    Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);  // This plugin for QWindow classes
    Q_IMPORT_PLUGIN(DSServicePlugin);   // This plugin for QMediaPlayer classes
    
    1. All libs must be added manually
      (add into project config or with "pragma comment (lib, "")")
      For example:
      windows libs for my app (there are DirectX libs, networking libs, GUI libs and lins i dont even know):
    #pragma comment(lib, "Ws2_32.lib")
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "imm32.lib")
    #pragma comment(lib, "winmm.lib")
    #pragma comment(lib, "UxTheme.lib")
    #pragma comment(lib, "Version.lib")
    #pragma comment(lib, "Dwmapi.lib")
    #pragma comment(lib, "Mfplat.lib")
    #pragma comment(lib, "D3d9.lib")
    #pragma comment(lib, "Mfuuid.lib")
    #pragma comment(lib, "Mf.lib")
    #pragma comment(lib, "Dxva2.lib")
    #pragma comment(lib, "Evr.lib")
    

    Qt libs for my app:
    Be care with Debug versions (ended with "d"), so for my build i made #ifdef block

    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5MultimediaQuick_pd.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5MultimediaWidgetsd.lib")
    ... Here you need to add all qt libs you use in app, a lot of libs.
    You can add all of them, but it dramatically increase linkage time
    

    After adding all of libs and resolve all dependencies i finally build fully static app.
    image_1

    UPDATE
    after removing all unused libs i got list of qt libs:

    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5AccessibilitySupport.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Core.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5EventDispatcherSupport.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5FontDatabaseSupport.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Multimedia.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5MultimediaWidgets.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Network.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5OpenGL.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Test.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5ThemeSupport.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Widgets.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Xml.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtfreetype.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtharfbuzz.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtlibpng.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtmain.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtpcre2d.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\plugins\\mediaservice\\dsengine.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\plugins\\platforms\\qwindows.lib")
    

    Basically QT VS addin add some libs into msvc project config but not them all

    Hope this information will be helpfull


  • Moderators

    Check if the same happens in Qt 5.9.5 and if yes, report it as a bug to Qt bugtracker https://bugreports.qt.io



  • Hi there.
    #pragma comment(lib, "Ws2_32.lib")
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "imm32.lib")
    #pragma comment(lib, "imm32.lib")
    #pragma comment(lib, "winmm.lib")

    #pragma comment(lib, "c:\Qt\5.9\static\plugins\platforms\qwindowsd.lib")
    #pragma comment(lib, "c:\Qt\5.9\static\lib\qtlibpngd.lib")
    #pragma comment(lib, "c:\Qt\5.9\static\lib\qtharfbuzzd.lib")
    #pragma comment(lib, "c:\Qt\5.9\static\lib\qtpcre2d.lib")

    #pragma comment(lib, "UxTheme.lib")
    #pragma comment(lib, "Mincore.lib")
    #pragma comment(lib, "Version.lib")

    Adding these libs to my project reduces errors from 183 to 13, have some troubles with additional)
    Think i found some more and finally build static app )



  • Finally i build fully static app)
    But it contains a lot of windows dlls dependencies.

    Important things for static apps:

    1. All plugins disabled, so you need load it manually with "Q_IMPORT_PLUGIN"
      For example my app need 2 plugins:
    Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);  // This plugin for QWindow classes
    Q_IMPORT_PLUGIN(DSServicePlugin);   // This plugin for QMediaPlayer classes
    
    1. All libs must be added manually
      (add into project config or with "pragma comment (lib, "")")
      For example:
      windows libs for my app (there are DirectX libs, networking libs, GUI libs and lins i dont even know):
    #pragma comment(lib, "Ws2_32.lib")
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "imm32.lib")
    #pragma comment(lib, "winmm.lib")
    #pragma comment(lib, "UxTheme.lib")
    #pragma comment(lib, "Version.lib")
    #pragma comment(lib, "Dwmapi.lib")
    #pragma comment(lib, "Mfplat.lib")
    #pragma comment(lib, "D3d9.lib")
    #pragma comment(lib, "Mfuuid.lib")
    #pragma comment(lib, "Mf.lib")
    #pragma comment(lib, "Dxva2.lib")
    #pragma comment(lib, "Evr.lib")
    

    Qt libs for my app:
    Be care with Debug versions (ended with "d"), so for my build i made #ifdef block

    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5MultimediaQuick_pd.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5MultimediaWidgetsd.lib")
    ... Here you need to add all qt libs you use in app, a lot of libs.
    You can add all of them, but it dramatically increase linkage time
    

    After adding all of libs and resolve all dependencies i finally build fully static app.
    image_1

    UPDATE
    after removing all unused libs i got list of qt libs:

    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5AccessibilitySupport.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Core.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5EventDispatcherSupport.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5FontDatabaseSupport.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Multimedia.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5MultimediaWidgets.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Network.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5OpenGL.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Test.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5ThemeSupport.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Widgets.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\Qt5Xml.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtfreetype.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtharfbuzz.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtlibpng.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtmain.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\lib\\qtpcre2d.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\plugins\\mediaservice\\dsengine.lib")
    #pragma comment(lib, "c:\\Qt\\5.9.1\\static\\plugins\\platforms\\qwindows.lib")
    

    Basically QT VS addin add some libs into msvc project config but not them all

    Hope this information will be helpfull


Log in to reply