Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. build qt statically with zlib and openssl
Forum Updated to NodeBB v4.3 + New Features

build qt statically with zlib and openssl

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saeid0034
    wrote on last edited by
    #1

    Hi Im trying to statically build qt, the problem is I also want it to have zlib linked to it, but Im not sure to how to do it...
    by default its says Using system zlib is disabled... so what can I do to add zlib support to it then build?
    and also can anyone give me an minimal configure that only have like widget, core and svg module available..? (no qml, qtquick...) I want it to be as fast as possible to build...

    1 Reply Last reply
    0
    • S Offline
      S Offline
      saeid0034
      wrote on last edited by
      #2

      and also how can I build Qt with /MT and /MTd? so then I can create a fully static program..?

      1 Reply Last reply
      0
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by hskoglund
        #3

        Hi, in your first post you didn't mention the Qt version, compiler and OS version, but now that you mention /MT and /MTd that means MSVC2019 64-bit and then I'm guessing Qt 6.3.0 and Windows10/11?
        I'm not using the zlib and svg modules so I cannot help you there, but I do static MSVC 2019 builds with openssl included (so that no ssl .dlls are needed at runtime).

        One problem with static MSVC2019 builds that have ssl included, is that the ssl version that the Qt online installer offers is not sufficient, since those libs are not /MT compatible.
        Instead, I download my ssl libraries from Shining Light I've only used the 1.1x versions (had no success with the 3.0.x versions so far).

        Edit: I just tested a static ssl build on 6.3.0 MSVC2019 64-bit. Here is the .bat file I used:

        rem Builds 6.3.0 64-bit MSVC2019 to C:\Qt\6.3.0\staticssl
        rem
        rem Download Qt source and place it in C:\Qt\qt-everywhere-src-6.3.0
        rem Downlaod OpenSSL and install it one directory below: C:\Qt\qt-everywhere-src-6.3.0\OpenSSL-Win64
        rem
        rem When build is done and installed to C:\Qt\6.3.0\staticssl
        rem copy C:\qt\qt-everywhere-src-6.3.0\OpenSSL-Win32\lib\VC\static\libCrypto64MT.lib and libssl64MT.lib into C:\Qt\6.3.0\staticssl\lib\VC\static
        rem
        set OPENSSL_USE_STATIC_LIB=ON
        rem OPENSSL_LIBS="-lWs2_32 -lGdi32 -lAdvapi32 -lCrypt32 -lUser32 -lVC\static\libssl32MT -lVC\static\libcrypto32MT" 
        configure -prefix C:\Qt\6.3.0\staticssl -release -opensource -confirm-license -static -static-runtime -openssl-linked -DOPENSSL_USE_STATIC_LIB=ON -nomake tests -nomake examples -no-feature-accessibility -no-feature-dtls -no-feature-gssapi -no-feature-itemmodeltester -no-feature-testlib_selfcover -no-feature-tuiotouch -no-feature-valgrind -no-feature-lcdnumber -no-sql-sqlite -no-sql-mysql -no-sql-psql -no-pch -skip qt3d -skip qtactiveqt -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtimageformats -skip qtlottie -skip qtmqtt -skip qtmultimedia -skip qtnetworkauth -skip qtquick3d -skip qtquicktimeline -skip qtremoteobjects -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtsvg -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtcoap -skip qtopcua -skip opengl -skip qtpositioning -skip qtshadertools
        rem then type:
        rem cmake --build . --parallel
        rem cmake --install .
        

        Note: I only tested release-flavor builds.

        Also. when building Qt apps against the static version, for CMake builds you have to insert this line:

        set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
        

        if you're using qmake (and you;re on Qt Creator 7 or later) then it just works out of the box i.e. no fiddling with the /MT or /MD switches is needed :-)

        S 1 Reply Last reply
        2
        • hskoglundH hskoglund

          Hi, in your first post you didn't mention the Qt version, compiler and OS version, but now that you mention /MT and /MTd that means MSVC2019 64-bit and then I'm guessing Qt 6.3.0 and Windows10/11?
          I'm not using the zlib and svg modules so I cannot help you there, but I do static MSVC 2019 builds with openssl included (so that no ssl .dlls are needed at runtime).

          One problem with static MSVC2019 builds that have ssl included, is that the ssl version that the Qt online installer offers is not sufficient, since those libs are not /MT compatible.
          Instead, I download my ssl libraries from Shining Light I've only used the 1.1x versions (had no success with the 3.0.x versions so far).

          Edit: I just tested a static ssl build on 6.3.0 MSVC2019 64-bit. Here is the .bat file I used:

          rem Builds 6.3.0 64-bit MSVC2019 to C:\Qt\6.3.0\staticssl
          rem
          rem Download Qt source and place it in C:\Qt\qt-everywhere-src-6.3.0
          rem Downlaod OpenSSL and install it one directory below: C:\Qt\qt-everywhere-src-6.3.0\OpenSSL-Win64
          rem
          rem When build is done and installed to C:\Qt\6.3.0\staticssl
          rem copy C:\qt\qt-everywhere-src-6.3.0\OpenSSL-Win32\lib\VC\static\libCrypto64MT.lib and libssl64MT.lib into C:\Qt\6.3.0\staticssl\lib\VC\static
          rem
          set OPENSSL_USE_STATIC_LIB=ON
          rem OPENSSL_LIBS="-lWs2_32 -lGdi32 -lAdvapi32 -lCrypt32 -lUser32 -lVC\static\libssl32MT -lVC\static\libcrypto32MT" 
          configure -prefix C:\Qt\6.3.0\staticssl -release -opensource -confirm-license -static -static-runtime -openssl-linked -DOPENSSL_USE_STATIC_LIB=ON -nomake tests -nomake examples -no-feature-accessibility -no-feature-dtls -no-feature-gssapi -no-feature-itemmodeltester -no-feature-testlib_selfcover -no-feature-tuiotouch -no-feature-valgrind -no-feature-lcdnumber -no-sql-sqlite -no-sql-mysql -no-sql-psql -no-pch -skip qt3d -skip qtactiveqt -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtimageformats -skip qtlottie -skip qtmqtt -skip qtmultimedia -skip qtnetworkauth -skip qtquick3d -skip qtquicktimeline -skip qtremoteobjects -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtsvg -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtcoap -skip qtopcua -skip opengl -skip qtpositioning -skip qtshadertools
          rem then type:
          rem cmake --build . --parallel
          rem cmake --install .
          

          Note: I only tested release-flavor builds.

          Also. when building Qt apps against the static version, for CMake builds you have to insert this line:

          set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
          

          if you're using qmake (and you;re on Qt Creator 7 or later) then it just works out of the box i.e. no fiddling with the /MT or /MD switches is needed :-)

          S Offline
          S Offline
          saeid0034
          wrote on last edited by
          #4

          @hskoglund thank you very much, the config and skips do look good for my use
          Im in windows 10 and using vs2022 for compiling Qt5.13.3
          do the config work on this version too?

          1 Reply Last reply
          0
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #5

            Qt 5 is different (Qt builds with qmake) I don't have a .bat file for 5.13.3 but I have one for 5.15.2 32-bit (so I'm using 32-bit OpenSSL in this example)

            rem Download OpenSSL and install it one directory below: C:\Qt\qt-everywhere-src-5.15.2\OpenSSL-Win32
            rem This build will install to C:\Qt\5.15.2\staticssl
            rem
            rem When the build is done, for building Qt apps against it, copy C:\qt\qt-everywhere-src-5.15.2\OpenSSL-Win32\lib\VC\static\libCrypto32MT.lib and libssl32MT.lib into C:\Qt\5.15.2\staticssl\lib\VC\static
            rem
            set OPENSSL_DIR=C:\Qt\qt-everywhere-src-5.15.2\OpenSSL-Win32
            configure -prefix C:\Qt\5.15.2\staticssl -release -opensource -confirm-license -static -static-runtime -openssl-linked OPENSSL_INCDIR="%OPENSSL_DIR%\include" OPENSSL_LIBDIR="%OPENSSL_DIR%\lib" OPENSSL_LIBS="-lWs2_32 -lGdi32 -lAdvapi32 -lCrypt32 -lUser32 -lVC\static\libssl32MT -lVC\static\libcrypto32MT" -nomake tests -nomake examples -no-opengl -no-feature-accessibility -no-feature-bearermanagement -no-feature-dtls -no-feature-ftp -no-feature-gssapi -no-feature-itemmodeltester -no-feature-testlib_selfcover -no-feature-tuiotouch -no-feature-valgrind -no-feature-lcdnumber -no-sql-sqlite -no-sql-mysql -no-sql-psql -no-pch -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtlottie -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquick3d -skip qtquickcontrols -skip qtquickcontrols2 -skip qtquicktimeline -skip qtremoteobjects -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebglplugin -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns
            pause
            nmake
            nmake install
            

            I removed the -skip qtsvg above for you :-

            P.S. When I build a typical Qt Widgets 5.15.2 app against this static build, the .exe file arrives at 10 MB - 11 MB with working ssl and no .dll dependencies :-)

            S 1 Reply Last reply
            1
            • hskoglundH hskoglund

              Qt 5 is different (Qt builds with qmake) I don't have a .bat file for 5.13.3 but I have one for 5.15.2 32-bit (so I'm using 32-bit OpenSSL in this example)

              rem Download OpenSSL and install it one directory below: C:\Qt\qt-everywhere-src-5.15.2\OpenSSL-Win32
              rem This build will install to C:\Qt\5.15.2\staticssl
              rem
              rem When the build is done, for building Qt apps against it, copy C:\qt\qt-everywhere-src-5.15.2\OpenSSL-Win32\lib\VC\static\libCrypto32MT.lib and libssl32MT.lib into C:\Qt\5.15.2\staticssl\lib\VC\static
              rem
              set OPENSSL_DIR=C:\Qt\qt-everywhere-src-5.15.2\OpenSSL-Win32
              configure -prefix C:\Qt\5.15.2\staticssl -release -opensource -confirm-license -static -static-runtime -openssl-linked OPENSSL_INCDIR="%OPENSSL_DIR%\include" OPENSSL_LIBDIR="%OPENSSL_DIR%\lib" OPENSSL_LIBS="-lWs2_32 -lGdi32 -lAdvapi32 -lCrypt32 -lUser32 -lVC\static\libssl32MT -lVC\static\libcrypto32MT" -nomake tests -nomake examples -no-opengl -no-feature-accessibility -no-feature-bearermanagement -no-feature-dtls -no-feature-ftp -no-feature-gssapi -no-feature-itemmodeltester -no-feature-testlib_selfcover -no-feature-tuiotouch -no-feature-valgrind -no-feature-lcdnumber -no-sql-sqlite -no-sql-mysql -no-sql-psql -no-pch -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtlottie -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquick3d -skip qtquickcontrols -skip qtquickcontrols2 -skip qtquicktimeline -skip qtremoteobjects -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebglplugin -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns
              pause
              nmake
              nmake install
              

              I removed the -skip qtsvg above for you :-

              P.S. When I build a typical Qt Widgets 5.15.2 app against this static build, the .exe file arrives at 10 MB - 11 MB with working ssl and no .dll dependencies :-)

              S Offline
              S Offline
              saeid0034
              wrote on last edited by
              #6

              @hskoglund thank you very much, with no dll dependency you mean even ones like msvcp140_1.dll not needed anymore?! so fully static (same as using /MT option)?
              it would be awesome for my case...

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by
                #7

                Yes, even without msvcp140_1.dll :-)

                Of course the usual suspects like ntdll.dll, kernel32.dll, kernelbase.dll etc. are still needed, but they are present in all Windows 10/11 installations. So you should be able to copy your .exe file to any Windows PC.

                I just tested my build ..bat file above (the one for Qt 5.15.2 MSVC2019 32-bit):
                I downloaded the source for Qt 5.15.3 and built it with MSVC2019 32-bit and that .bat file.
                Then I tested on Qt 5.15.2 Example SecureSocketClient (that's a good example to make sure ssl communication works fine without any .dlls).
                When I built it with Qt 5.15.3 32-bit static the .exe file size is just below 13 MB.
                If you're using Qt Creator 7 (the current one) and qmake for building then you don't have to think about the /MT and /MD compiler switches, Qt Creator takes care of it now :-)
                (However for CMake builds you still have to add one line, please see my updated first post above, maybe that will be fixed in Qt Creator 8).

                P.S. I tried the SecureSocketClient example also with a fresh Qt 6.3.0 MSVC2019 64-bit build, and then the size of the .exe grows to 18 MB. Perhaps 1 or 2 MB is due to the switch to 64-bit, but also I think I can improve the .bat I used (in my first post above).

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved