Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. trying to build a static Qt for Windows
QtWS25 Last Chance

trying to build a static Qt for Windows

Scheduled Pinned Locked Moved Solved Installation and Deployment
18 Posts 3 Posters 4.1k Views
  • 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 30 Apr 2024, 18:01 last edited by
    #1

    Hi all -

    Once again, I need to build a standalone application (the customer is insisting on this instead of using an .msi installer). I do this so infrequently, that my notes from the previous effort are out of date.

    I'm looking at this page:, and trying to perform step 3. This is my command:

    c:\Qt\6.5.3\Src\configure.bat -static -static-runtime -release -skip qtwebengine -Wno-dev 
    

    I'm getting several warnings (and my attempt to build fails, but more on that later). Can someone tell me whether any of these are going to prove fatal to my build? This is just a snippet of the entire output:

    c:\qt_static>c:\Qt\6.5.3\Src\configure.bat -static -static-runtime -release -skip qtwebengine -Wno-dev
    + cd qtbase
    + c:\Qt\6.5.3\Src\qtbase\configure.bat -top-level -static -static-runtime -release -skip qtwebengine -Wno-dev
    -- Windows 10 SDK version:
    'C:/Program Files/CMake/bin/cmake.exe' '-DBUILD_qtwebengine=OFF' '-DBUILD_SHARED_LIBS=OFF' '-DCMAKE_BUILD_TYPE=Release' '-DINPUT_static_runtime=yes' '-DINPUT_wflags=no-dev' '-G' 'MinGW Makefiles' 'C:/Qt/6.5.3/Src'
    CMake Warning at qtbase/cmake/QtAutoDetect.cmake:70 (message):
      The officially supported CMake generator for building Qt is Ninja.  You are
      using: 'MinGW Makefiles' instead.  Thus, you might encounter issues.  Use
      at your own risk.
    -- Configuring submodule 'qtbase'
                -DCMAKE_C_FLAGS_DEBUG=-g
                -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -O2
                -DCMAKE_C_FLAGS_RELWITHDEBINFO=-g -DNDEBUG -O2
                -DCMAKE_CXX_FLAGS_DEBUG=-g
                -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -O2
                -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-g -DNDEBUG -O2
                -DCMAKE_OBJCOPY=C:/Qt/Tools/mingw1120_64/bin/objcopy.exe
                -DCMAKE_C_STANDARD=11
                -DCMAKE_C_STANDARD_REQUIRED=ON
                -DCMAKE_CXX_STANDARD=17
                -DCMAKE_CXX_STANDARD_REQUIRED=ON
                -DCMAKE_MODULE_PATH:STRING=C:/Qt/6.5.3/Src/qtbase/cmake/platforms
    CMake Warning (dev) at C:/qt_static/qtbase/lib/cmake/Qt6Qml/Qt6QmlBuildInternals.cmake:404 (message):
      INSTALL_SOURCE_QMLTYPES option is deprecated and should not be used.
      Please port your module to use declarative type registration.
    Call Stack (most recent call first):
      qt3d/src/quick3d/imports/render/CMakeLists.txt:10 (qt_internal_add_qml_module)
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    -- Could NOT find Clang (missing: Clang_DIR)
    -- Could NOT find Clang (missing: Clang_DIR)
    -- Configuring submodule 'qtwebview'
    -- Could NOT find Qt6WebEngineCore (missing: Qt6WebEngineCore_DIR)
    CMake Warning at C:/qt_static/qtbase/lib/cmake/Qt6/Qt6Config.cmake:214 (message):
      Failed to find optional Qt component "WebEngineCore".
    
      Expected Config file at
      "C:/qt_static/qtbase/lib/cmake/Qt6WebEngineCore/Qt6WebEngineCoreConfig.cmake"
      does NOT exist
    
    -- Could NOT find Qt6WebEngineQuick (missing: Qt6WebEngineQuick_DIR)
    CMake Warning at C:/qt_static/qtbase/lib/cmake/Qt6/Qt6Config.cmake:214 (message):
      Failed to find optional Qt component "WebEngineQuick".
    
      Expected Config file at
      "C:/qt_static/qtbase/lib/cmake/Qt6WebEngineQuick/Qt6WebEngineQuickConfig.cmake"
      does NOT exist
    

    Thanks for any insights...

    S 1 Reply Last reply 30 Apr 2024, 19:06
    0
    • C cristian-adam
      1 May 2024, 18:27

      @mzimmers Then try building a Qt Location example with a Kit that has your static Qt. And see how that works out.

      M Offline
      M Offline
      mzimmers
      wrote on 1 May 2024, 19:34 last edited by mzimmers 5 Jan 2024, 20:32
      #12

      @cristian-adam if I understand you, that's what I just did (my application does use QGeoLocation).

      Or, are you suggesting I try a different application that also uses Qt Location?

      EDIT:

      Per @cristian-adam 's suggestion, I used one of the supplied Qt applications, and it built. On a hunch, I completely deleted the build directory for my application (doing a clean from Creator was not sufficient), and rebuilt. My executable is now ~20x the size of the prior version. Once I'm done uploading, I'll test it and report back.

      EDIT 2:

      It seems to work! Here are the steps I took (in summary form):

      1. make sure you have all the necessary tools added to your PATH:
        • your toolchain (eg: C:\qt\tools\mingw1120_64\bin)
        • Ninja (eg: C:\Qt\Tools\Ninja)
      2. from a command prompt, create and enter a directory for your static build (eg: c:\qt_static)
      3. run a configure command with these options (you might add more options, such as some "-skip"s to your configuration):
          c:\Qt\6.5.3\Src\configure.bat -prefix c:\qt_static -static -static-runtime -release -Wno-dev 
      
      1. if anything goes wrong with your configuration, or if you want to change something, delete the entire contents of your directory created in step 2. As an alternative, you can try @SGaist's suggestion of the "-redo" option, but read up on it before using; its behavior may surprise you.
      2. run:
          cmake --build . --parallel
          cmake --install .
      

      If all went well, you have now successfully built and installed a static Qt version. To use this static version, perform the following steps:

      1. from Creator -> Preferences -> Kits -> Qt Versions, manually add the version you just created. Reference the qmake6.exe file in the bin directory of your new Qt version. Apply this change.
      2. now go to the Kits tab, and create a new kit, named whatever you like. In the line "Qt version:" select the version you entered in the previous step. Double-check that the compilers and debugger are the correct versions for your kit. Apply and hit OK.
      3. choose your newly-created kit for use with your application. Do this from the Projects->Manage Kits... button. Once you've enabled your new kit, you can select it from the icon in the leftmost column of Creator (I don't know what that icon is called).

      That should do it. When building static executables, be prepared for a huge jump in file size (mine is on the order of 20X). Also, I'd recommend you not try to build a static debug image (they get insanely large); stick to release.

      If anyone has any corrections to this list, please let me know. Thanks to everyone for the help on this.

      1 Reply Last reply
      2
      • M mzimmers
        30 Apr 2024, 18:01

        Hi all -

        Once again, I need to build a standalone application (the customer is insisting on this instead of using an .msi installer). I do this so infrequently, that my notes from the previous effort are out of date.

        I'm looking at this page:, and trying to perform step 3. This is my command:

        c:\Qt\6.5.3\Src\configure.bat -static -static-runtime -release -skip qtwebengine -Wno-dev 
        

        I'm getting several warnings (and my attempt to build fails, but more on that later). Can someone tell me whether any of these are going to prove fatal to my build? This is just a snippet of the entire output:

        c:\qt_static>c:\Qt\6.5.3\Src\configure.bat -static -static-runtime -release -skip qtwebengine -Wno-dev
        + cd qtbase
        + c:\Qt\6.5.3\Src\qtbase\configure.bat -top-level -static -static-runtime -release -skip qtwebengine -Wno-dev
        -- Windows 10 SDK version:
        'C:/Program Files/CMake/bin/cmake.exe' '-DBUILD_qtwebengine=OFF' '-DBUILD_SHARED_LIBS=OFF' '-DCMAKE_BUILD_TYPE=Release' '-DINPUT_static_runtime=yes' '-DINPUT_wflags=no-dev' '-G' 'MinGW Makefiles' 'C:/Qt/6.5.3/Src'
        CMake Warning at qtbase/cmake/QtAutoDetect.cmake:70 (message):
          The officially supported CMake generator for building Qt is Ninja.  You are
          using: 'MinGW Makefiles' instead.  Thus, you might encounter issues.  Use
          at your own risk.
        -- Configuring submodule 'qtbase'
                    -DCMAKE_C_FLAGS_DEBUG=-g
                    -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -O2
                    -DCMAKE_C_FLAGS_RELWITHDEBINFO=-g -DNDEBUG -O2
                    -DCMAKE_CXX_FLAGS_DEBUG=-g
                    -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -O2
                    -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-g -DNDEBUG -O2
                    -DCMAKE_OBJCOPY=C:/Qt/Tools/mingw1120_64/bin/objcopy.exe
                    -DCMAKE_C_STANDARD=11
                    -DCMAKE_C_STANDARD_REQUIRED=ON
                    -DCMAKE_CXX_STANDARD=17
                    -DCMAKE_CXX_STANDARD_REQUIRED=ON
                    -DCMAKE_MODULE_PATH:STRING=C:/Qt/6.5.3/Src/qtbase/cmake/platforms
        CMake Warning (dev) at C:/qt_static/qtbase/lib/cmake/Qt6Qml/Qt6QmlBuildInternals.cmake:404 (message):
          INSTALL_SOURCE_QMLTYPES option is deprecated and should not be used.
          Please port your module to use declarative type registration.
        Call Stack (most recent call first):
          qt3d/src/quick3d/imports/render/CMakeLists.txt:10 (qt_internal_add_qml_module)
        This warning is for project developers.  Use -Wno-dev to suppress it.
        
        -- Could NOT find Clang (missing: Clang_DIR)
        -- Could NOT find Clang (missing: Clang_DIR)
        -- Configuring submodule 'qtwebview'
        -- Could NOT find Qt6WebEngineCore (missing: Qt6WebEngineCore_DIR)
        CMake Warning at C:/qt_static/qtbase/lib/cmake/Qt6/Qt6Config.cmake:214 (message):
          Failed to find optional Qt component "WebEngineCore".
        
          Expected Config file at
          "C:/qt_static/qtbase/lib/cmake/Qt6WebEngineCore/Qt6WebEngineCoreConfig.cmake"
          does NOT exist
        
        -- Could NOT find Qt6WebEngineQuick (missing: Qt6WebEngineQuick_DIR)
        CMake Warning at C:/qt_static/qtbase/lib/cmake/Qt6/Qt6Config.cmake:214 (message):
          Failed to find optional Qt component "WebEngineQuick".
        
          Expected Config file at
          "C:/qt_static/qtbase/lib/cmake/Qt6WebEngineQuick/Qt6WebEngineQuickConfig.cmake"
          does NOT exist
        

        Thanks for any insights...

        S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 30 Apr 2024, 19:06 last edited by
        #2

        Hi,

        For qt3d, it should not, the option is deprecated but has not been removed from that version of Qt.

        As for qtwebview, it won't be usable as is since Windows does not have a default web view unlike macOS.

        In the absolute, I would recommend building only the modules you use and add others when need arises. This will save you time and space.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply 30 Apr 2024, 19:31
        1
        • S SGaist
          30 Apr 2024, 19:06

          Hi,

          For qt3d, it should not, the option is deprecated but has not been removed from that version of Qt.

          As for qtwebview, it won't be usable as is since Windows does not have a default web view unlike macOS.

          In the absolute, I would recommend building only the modules you use and add others when need arises. This will save you time and space.

          M Offline
          M Offline
          mzimmers
          wrote on 30 Apr 2024, 19:31 last edited by mzimmers
          #3

          @SGaist thanks. I'll try trial and error to see how many modules I can skip.

          What about this one:

          -- Could NOT find Clang (missing: Clang_DIR)
          

          Is this something I should address?

          Also, I remember something from the old days, when we had to perform a step to "undo" a configuration before reconfiguring. Is this still the case? There's nothing about that on the web page.

          S 1 Reply Last reply 30 Apr 2024, 19:47
          0
          • M mzimmers
            30 Apr 2024, 19:31

            @SGaist thanks. I'll try trial and error to see how many modules I can skip.

            What about this one:

            -- Could NOT find Clang (missing: Clang_DIR)
            

            Is this something I should address?

            Also, I remember something from the old days, when we had to perform a step to "undo" a configuration before reconfiguring. Is this still the case? There's nothing about that on the web page.

            S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 30 Apr 2024, 19:47 last edited by
            #4

            If memory serves well clang is used for qdoc in order to parse the sources. There might be other uses but I don't remember right now.

            There's now a -redo option with some caveats when passing additional flags.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply 30 Apr 2024, 20:14
            1
            • S SGaist
              30 Apr 2024, 19:47

              If memory serves well clang is used for qdoc in order to parse the sources. There might be other uses but I don't remember right now.

              There's now a -redo option with some caveats when passing additional flags.

              M Offline
              M Offline
              mzimmers
              wrote on 30 Apr 2024, 20:14 last edited by
              #5

              @SGaist so, acting on your advice, I skipped a few more modules:

              c:\Qt\6.5.3\Src\configure.bat -prefix c:\qt_static -static -static-runtime -release -skip qt3d, qt5compat, qtactiveqt, qtcharts, qtdatavis3d, qtdoc, qtgrpc, qtinsighttracker, qtmultimedia, qtquick3d, qtquick3dphysics, qtquicktimeline, qtwayland, qtwebchannel, qtwebengine, qtwebview -Wno-dev 
              

              Seems to work OK.

              Now, when I execute:

              cmake --build . --parallel
              

              I get this error:

              [  5%] Built target Bootstrap
              [  5%] Built target BundledLibjpeg
              [  5%] Linking CXX static library ..\..\..\lib\libQt6BundledHarfbuzz.a
              [  5%] Built target BundledHarfbuzz
              mingw32-make.exe: *** [Makefile:145: all] Error 2
              

              and it stops. Looking back in the output, the only error I can find was this:

              Unable to remove file: "C:/qt_static/qtbase/include/QtPositioningQuick/qtpositioningquickversion.h" to "C:/qt_static/qtbase/include/QtPositioningQuick/.syncqt_staging/qtpositioningquickversion.h" error: (2)No such file or directory
              mingw32-make.exe[2]: *** [qtpositioning\src\positioningquick\CMakeFiles\PositioningQuick_sync_headers.dir\build.make:91: qtpositioning/src/positioningquick/PositioningQuick_syncqt_timestamp] Error 2
              mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:73713: qtpositioning/src/positioningquick/CMakeFiles/PositioningQuick_sync_headers.dir/all] Error 2
              

              I'm not sure what to make of this...

              C 1 Reply Last reply 30 Apr 2024, 20:18
              0
              • M mzimmers
                30 Apr 2024, 20:14

                @SGaist so, acting on your advice, I skipped a few more modules:

                c:\Qt\6.5.3\Src\configure.bat -prefix c:\qt_static -static -static-runtime -release -skip qt3d, qt5compat, qtactiveqt, qtcharts, qtdatavis3d, qtdoc, qtgrpc, qtinsighttracker, qtmultimedia, qtquick3d, qtquick3dphysics, qtquicktimeline, qtwayland, qtwebchannel, qtwebengine, qtwebview -Wno-dev 
                

                Seems to work OK.

                Now, when I execute:

                cmake --build . --parallel
                

                I get this error:

                [  5%] Built target Bootstrap
                [  5%] Built target BundledLibjpeg
                [  5%] Linking CXX static library ..\..\..\lib\libQt6BundledHarfbuzz.a
                [  5%] Built target BundledHarfbuzz
                mingw32-make.exe: *** [Makefile:145: all] Error 2
                

                and it stops. Looking back in the output, the only error I can find was this:

                Unable to remove file: "C:/qt_static/qtbase/include/QtPositioningQuick/qtpositioningquickversion.h" to "C:/qt_static/qtbase/include/QtPositioningQuick/.syncqt_staging/qtpositioningquickversion.h" error: (2)No such file or directory
                mingw32-make.exe[2]: *** [qtpositioning\src\positioningquick\CMakeFiles\PositioningQuick_sync_headers.dir\build.make:91: qtpositioning/src/positioningquick/PositioningQuick_syncqt_timestamp] Error 2
                mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:73713: qtpositioning/src/positioningquick/CMakeFiles/PositioningQuick_sync_headers.dir/all] Error 2
                

                I'm not sure what to make of this...

                C Offline
                C Offline
                cristian-adam
                wrote on 30 Apr 2024, 20:18 last edited by
                #6

                @mzimmers

                The officially supported CMake generator for building Qt is Ninja. You are
                using: 'MinGW Makefiles' instead. Thus, you might encounter issues. Use
                at your own risk

                Make sure you have Ninja in path.

                M 2 Replies Last reply 30 Apr 2024, 20:59
                1
                • C cristian-adam
                  30 Apr 2024, 20:18

                  @mzimmers

                  The officially supported CMake generator for building Qt is Ninja. You are
                  using: 'MinGW Makefiles' instead. Thus, you might encounter issues. Use
                  at your own risk

                  Make sure you have Ninja in path.

                  M Offline
                  M Offline
                  mzimmers
                  wrote on 30 Apr 2024, 20:59 last edited by
                  #7

                  @cristian-adam OK, I didn't think that was essential, but I'll try that and report back. Thanks...

                  1 Reply Last reply
                  0
                  • C cristian-adam
                    30 Apr 2024, 20:18

                    @mzimmers

                    The officially supported CMake generator for building Qt is Ninja. You are
                    using: 'MinGW Makefiles' instead. Thus, you might encounter issues. Use
                    at your own risk

                    Make sure you have Ninja in path.

                    M Offline
                    M Offline
                    mzimmers
                    wrote on 1 May 2024, 17:17 last edited by
                    #8

                    @cristian-adam OK, I added Ninja to my system and my path, and that did seem to make a difference. The configuration completed with only a couple warnings, and the build and installs looks successful.

                    Is there a way to determine that this is truly a static build? I ask because when I use it, my executable still looks for some .dll files.image_480.png

                    I'm not sure whether this is because my Qt build isn't static, or because I'm building my application incorrectly.

                    Any suggestions for isolating the problem here?

                    C 1 Reply Last reply 1 May 2024, 17:44
                    0
                    • M mzimmers
                      1 May 2024, 17:17

                      @cristian-adam OK, I added Ninja to my system and my path, and that did seem to make a difference. The configuration completed with only a couple warnings, and the build and installs looks successful.

                      Is there a way to determine that this is truly a static build? I ask because when I use it, my executable still looks for some .dll files.image_480.png

                      I'm not sure whether this is because my Qt build isn't static, or because I'm building my application incorrectly.

                      Any suggestions for isolating the problem here?

                      C Offline
                      C Offline
                      cristian-adam
                      wrote on 1 May 2024, 17:44 last edited by
                      #9

                      @mzimmers does your qt6 build have a Qt6Location.dll?

                      If so, it means that QtLocation didn't get the memo that it's doing a static build ...

                      M 1 Reply Last reply 1 May 2024, 17:52
                      1
                      • C cristian-adam
                        1 May 2024, 17:44

                        @mzimmers does your qt6 build have a Qt6Location.dll?

                        If so, it means that QtLocation didn't get the memo that it's doing a static build ...

                        M Offline
                        M Offline
                        mzimmers
                        wrote on 1 May 2024, 17:52 last edited by
                        #10

                        @cristian-adam I'm not sure I'm looking in the correct location, but:
                        Screenshot 2024-05-01 105212.png

                        C 1 Reply Last reply 1 May 2024, 18:27
                        0
                        • M mzimmers
                          1 May 2024, 17:52

                          @cristian-adam I'm not sure I'm looking in the correct location, but:
                          Screenshot 2024-05-01 105212.png

                          C Offline
                          C Offline
                          cristian-adam
                          wrote on 1 May 2024, 18:27 last edited by
                          #11

                          @mzimmers Then try building a Qt Location example with a Kit that has your static Qt. And see how that works out.

                          M 1 Reply Last reply 1 May 2024, 19:34
                          1
                          • C cristian-adam
                            1 May 2024, 18:27

                            @mzimmers Then try building a Qt Location example with a Kit that has your static Qt. And see how that works out.

                            M Offline
                            M Offline
                            mzimmers
                            wrote on 1 May 2024, 19:34 last edited by mzimmers 5 Jan 2024, 20:32
                            #12

                            @cristian-adam if I understand you, that's what I just did (my application does use QGeoLocation).

                            Or, are you suggesting I try a different application that also uses Qt Location?

                            EDIT:

                            Per @cristian-adam 's suggestion, I used one of the supplied Qt applications, and it built. On a hunch, I completely deleted the build directory for my application (doing a clean from Creator was not sufficient), and rebuilt. My executable is now ~20x the size of the prior version. Once I'm done uploading, I'll test it and report back.

                            EDIT 2:

                            It seems to work! Here are the steps I took (in summary form):

                            1. make sure you have all the necessary tools added to your PATH:
                              • your toolchain (eg: C:\qt\tools\mingw1120_64\bin)
                              • Ninja (eg: C:\Qt\Tools\Ninja)
                            2. from a command prompt, create and enter a directory for your static build (eg: c:\qt_static)
                            3. run a configure command with these options (you might add more options, such as some "-skip"s to your configuration):
                                c:\Qt\6.5.3\Src\configure.bat -prefix c:\qt_static -static -static-runtime -release -Wno-dev 
                            
                            1. if anything goes wrong with your configuration, or if you want to change something, delete the entire contents of your directory created in step 2. As an alternative, you can try @SGaist's suggestion of the "-redo" option, but read up on it before using; its behavior may surprise you.
                            2. run:
                                cmake --build . --parallel
                                cmake --install .
                            

                            If all went well, you have now successfully built and installed a static Qt version. To use this static version, perform the following steps:

                            1. from Creator -> Preferences -> Kits -> Qt Versions, manually add the version you just created. Reference the qmake6.exe file in the bin directory of your new Qt version. Apply this change.
                            2. now go to the Kits tab, and create a new kit, named whatever you like. In the line "Qt version:" select the version you entered in the previous step. Double-check that the compilers and debugger are the correct versions for your kit. Apply and hit OK.
                            3. choose your newly-created kit for use with your application. Do this from the Projects->Manage Kits... button. Once you've enabled your new kit, you can select it from the icon in the leftmost column of Creator (I don't know what that icon is called).

                            That should do it. When building static executables, be prepared for a huge jump in file size (mine is on the order of 20X). Also, I'd recommend you not try to build a static debug image (they get insanely large); stick to release.

                            If anyone has any corrections to this list, please let me know. Thanks to everyone for the help on this.

                            1 Reply Last reply
                            2
                            • M mzimmers has marked this topic as solved on 1 May 2024, 20:32
                            • C Offline
                              C Offline
                              cristian-adam
                              wrote on 1 May 2024, 21:29 last edited by
                              #13

                              If the size of the final application is an issue, you can enable for Qt's configure the -ltcg (link time code generation) option!

                              Then for your application set the CMAKE_INTERPROCEDURAL_OPTIMIZATION CMake variable to ON.

                              This way the linker can have a look at the whole application and its Qt dependencies and create the most optimal version of the executable.

                              See https://www.qt.io/blog/2019/01/02/qt-applications-lto for more information.

                              Note that not all applications work with LTO and it might be that the MinGW linker can fail or take a long time.

                              M 1 Reply Last reply 1 May 2024, 21:57
                              1
                              • C cristian-adam
                                1 May 2024, 21:29

                                If the size of the final application is an issue, you can enable for Qt's configure the -ltcg (link time code generation) option!

                                Then for your application set the CMAKE_INTERPROCEDURAL_OPTIMIZATION CMake variable to ON.

                                This way the linker can have a look at the whole application and its Qt dependencies and create the most optimal version of the executable.

                                See https://www.qt.io/blog/2019/01/02/qt-applications-lto for more information.

                                Note that not all applications work with LTO and it might be that the MinGW linker can fail or take a long time.

                                M Offline
                                M Offline
                                mzimmers
                                wrote on 1 May 2024, 21:57 last edited by
                                #14

                                @cristian-adam thanks for the suggestion. Can you tell me where in Creator I enter these?

                                Thanks...

                                1 Reply Last reply
                                0
                                • C Offline
                                  C Offline
                                  cristian-adam
                                  wrote on 2 May 2024, 12:10 last edited by
                                  #15

                                  First is for Qt's configure.bat call:

                                  $ c:\Qt\6.5.3\Src\configure.bat -prefix c:\qt_static -ltcg -static -static-runtime -release -Wno-dev
                                  

                                  Second is for your application's CMake parameters as seen at https://doc.qt.io/qtcreator/creator-build-settings-cmake.html#current-configuration

                                  alt text

                                  M 1 Reply Last reply 2 May 2024, 14:53
                                  2
                                  • C cristian-adam referenced this topic on 2 May 2024, 13:44
                                  • C cristian-adam
                                    2 May 2024, 12:10

                                    First is for Qt's configure.bat call:

                                    $ c:\Qt\6.5.3\Src\configure.bat -prefix c:\qt_static -ltcg -static -static-runtime -release -Wno-dev
                                    

                                    Second is for your application's CMake parameters as seen at https://doc.qt.io/qtcreator/creator-build-settings-cmake.html#current-configuration

                                    alt text

                                    M Offline
                                    M Offline
                                    mzimmers
                                    wrote on 2 May 2024, 14:53 last edited by mzimmers 5 Feb 2024, 14:55
                                    #16

                                    @cristian-adam thanks for the clarification. I started over (deleted everything from my static directory), added the configuration variable you cited:

                                    Screenshot 2024-05-02 075444.png
                                    and ran this command:

                                    c:\Qt\6.5.3\Src\configure.bat -prefix c:\qt_static -ltcg -static -static-runtime -release -skip qt3d -skip qt5compat -skip qtactiveqt -skip qtcharts -skip qtdatavis3d -skip qtdoc -skip qtgrpc -skip qtinsighttracker -skip qtmultimedia -skip qtquick3d -skip qtquick3dphysics -skip qtquicktimeline -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebview -Wno-dev 
                                    

                                    The configure returned successfully (though it did have some small errors), but the build command failed here:

                                    [579/7750] Linking CXX executable qtbase\bin\cmake_automoc_parser.exe
                                    FAILED: qtbase/bin/cmake_automoc_parser.exe
                                    C:\WINDOWS\system32\cmd.exe /C "cd . && C:\Qt\Tools\mingw1120_64\bin\c++.exe -DNDEBUG -O2 -flto=auto -fno-fat-lto-objects -static -Wl,--gc-sections qtbase/src/tools/cmake_automoc_parser/CMakeFiles/cmake_automoc_parser.dir/cmake_automoc_parser_resource.rc.obj qtbase/src/tools/cmake_automoc_parser/CMakeFiles/cmake_automoc_parser.dir/main.cpp.obj qtbase/src/tools/cmake_automoc_parser/CMakeFiles/cmake_automoc_parser.dir/cmake_automoc_parser_longpath.rc.obj -o qtbase\bin\cmake_automoc_parser.exe -Wl,--out-implib,qtbase\src\tools\cmake_automoc_parser\libcmake_automoc_parser.dll.a -Wl,--major-image-version,0,--minor-image-version,0  qtbase/src/tools/bootstrap/libBootstrap.a  -ladvapi32  -lnetapi32  -lole32  -lshell32  -luser32  -luuid  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
                                    C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: qtbase/src/tools/cmake_automoc_parser/CMakeFiles/cmake_automoc_parser.dir/main.cpp.obj: plugin needed to handle lto object
                                    C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
                                    collect2.exe: error: ld returned 1 exit status
                                    [608/7750] Building CXX object qtbase/src/3rdparty/harfbuzz-ng/CMakeFiles/BundledHarfbuzz.dir/src/hb-subset.cc.obj
                                    ninja: build stopped: subcommand failed.
                                    

                                    Any idea what might be going on here?

                                    Also, the configuration summary shows that I'm including language support for all available languages. I'd like to get rid of most of these. Do you know the option for this?

                                    Thanks...

                                    1 Reply Last reply
                                    0
                                    • C Offline
                                      C Offline
                                      cristian-adam
                                      wrote on 2 May 2024, 16:13 last edited by
                                      #17

                                      This looks like a bug in Qt. I'm not sure if -ltcg is tested regularly. Please do create a bug report at https://bugreports.qt.io/.

                                      You can then only test CMAKE_INTERPROCEDURAL_OPTIMIZATION with your application.

                                      M 1 Reply Last reply 2 May 2024, 16:25
                                      0
                                      • C cristian-adam
                                        2 May 2024, 16:13

                                        This looks like a bug in Qt. I'm not sure if -ltcg is tested regularly. Please do create a bug report at https://bugreports.qt.io/.

                                        You can then only test CMAKE_INTERPROCEDURAL_OPTIMIZATION with your application.

                                        M Offline
                                        M Offline
                                        mzimmers
                                        wrote on 2 May 2024, 16:25 last edited by
                                        #18

                                        @cristian-adam submitted.

                                        Thanks.

                                        1 Reply Last reply
                                        1
                                        • hskoglundH hskoglund referenced this topic on 22 Jul 2024, 05:39

                                        10/18

                                        1 May 2024, 17:52

                                        • Login

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