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. Creating a static linked exe - what did I miss?
QtWS25 Last Chance

Creating a static linked exe - what did I miss?

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
12 Posts 2 Posters 3.0k 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.
  • Z Offline
    Z Offline
    Zeblote
    wrote on last edited by Zeblote
    #1

    So, I finally managed to puzzle together a static build from various more or less outdated guides. Now I want to make sure that all the steps I did for this were actually necessary and correct, and what's missing.

    Here's how I did it:

    1. Install QT with these components, to default path:
      alt text

    2. Download jom and unzip it to C:\Qt\Jom\jom.exe

    3. Create a folder C:\Qt\5.9.3\static next to the default C:\Qt\5.9.3\Src

    4. Start an "x64 Native Tools Command Prompt for VS 2017" and run commands:

    • cd C:\Qt\5.9.3\static
    • set QTDIR=C:\Qt\5.9.3\Src\qtbase
    • set PATH=C:\Qt\5.9.3\Src\qtbase\bin;%PATH%
    1. Build static version of Qt:
    • C:\Qt\5.9.3\Src\configure.bat -prefix C:\Qt\5.9.3\static -debug-and-release -static -static-runtime -nomake examples -nomake tests -no-icu -optimize-size -opensource -confirm-license
    • C:\Qt\Jom\jom.exe
    • C:\Qt\Jom\jom.exe install
    1. Add the static version to Qt Creator
    • alt text
    • alt text
    1. Create a template project with this kit
    • Debug build crashes on start
    • Release build runs

    Soo... that's it?

    Now I have a whole bunch of open questions, obviously I missed something:

    1. What is an installed prefix build?
    2. Why doesn't the debug build work?
    3. Why is the release build 15MB huge for an empty window?
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      1. The usual way to build and install Qt is to use an out of source build and call nmake/mingw32-make install when done.
      2. Don't know, not enough details
      3. You are using a static build of Qt and I assume you are using a QWidget so you have three modules linked: core, gui and widgets.

      Static builds do not make smaller applications executable. It pulls in every bit of code need from all the dependencies of said executable.

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

      1 Reply Last reply
      1
      • Z Offline
        Z Offline
        Zeblote
        wrote on last edited by
        #3

        @SGaist said in Creating a static linked exe - what did I miss?:

        Hi,

        1. The usual way to build and install Qt is to use an out of source build and call nmake/mingw32-make install when done.
        2. Don't know, not enough details
        3. You are using a static build of Qt and I assume you are using a QWidget so you have three modules linked: core, gui and widgets.
          Static builds do not make smaller applications executable. It pulls in every bit of code need from all the dependencies of said executable.

        I see. I've tried changing the build command to build to another folder with the prefix thing, but it did not compile. Is something missing?

        • configure.bat -prefix C:\Qt\5.9.3\static -debug-and-release -opensource -static -static-runtime -nomake examples -nomake tests -no-icu -optimize-size -confirm-license
        • C:\Qt\Jom\jom.exe

        https://www.dropbox.com/s/al9x7wgg9vggwfh/log.txt?dl=0

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You called configure in the same folder without cleaning first ?

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

          Z 1 Reply Last reply
          0
          • SGaistS SGaist

            You called configure in the same folder without cleaning first ?

            Z Offline
            Z Offline
            Zeblote
            wrote on last edited by Zeblote
            #5

            @SGaist said in Creating a static linked exe - what did I miss?:

            You called configure in the same folder without cleaning first ?

            I used C:\Qt\Jom\jom.exe distclean first, is that still the correct command?


            Edit: I forgot to switch to the new "static" folder before running the build command. It compiled fine this time.

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zeblote
              wrote on last edited by Zeblote
              #6

              That took care of the installed build warning, but the one about a missing qmlscene remains.

              alt text

              Is this a problem if I'm not using any qml? I assume it can be ignored.

              -optimize-size also reduced the size of the exe to 13MB, which can be further reduced to 5MB with UPX. This seems fine for now considering it's with a static runtime and everything.

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zeblote
                wrote on last edited by
                #7

                That still didn't solve the problem with the debug build though. It will instantly show this error:

                alt text

                Not a major problem as I can just debug it with the default, non-static version, but still curious what could cause it? I have no idea what kind of log files Qt writes that might be relevant here.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  No it's not, it's only used for QML.

                  Did you check the backtrace ?

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

                  Z 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    No it's not, it's only used for QML.

                    Did you check the backtrace ?

                    Z Offline
                    Z Offline
                    Zeblote
                    wrote on last edited by
                    #9

                    @SGaist said in Creating a static linked exe - what did I miss?:

                    Did you check the backtrace ?

                    It breaks here:

                    alt text

                    alt text

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      Zeblote
                      wrote on last edited by Zeblote
                      #10

                      I just noticed that this testapp_plugin_import.cpp loads a whole bunch of stuff that I don't use.

                      alt text

                      Could this be a reason for the exe file being huge?
                      I tried disabling them in the .pro file using QTPLUGIN -= qgif, but it changed nothing (this file still looks the same after rebuild).

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Did you re-run qmake before building ?

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

                        Z 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Did you re-run qmake before building ?

                          Z Offline
                          Z Offline
                          Zeblote
                          wrote on last edited by Zeblote
                          #12

                          @SGaist said in Creating a static linked exe - what did I miss?:

                          Did you re-run qmake before building ?

                          Yes, I even deleted the entire build folder to make sure. It re-writes the plugin imports exactly the same.
                          Manually editing this file to remove the unnecessary plugins shrinks the exe by 1MB (or 300KB after packing), so it doesn't change all that much

                          1 Reply Last reply
                          0

                          • Login

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