Creating a static linked exe - what did I miss?



  • 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?

  • Lifetime Qt Champion

    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.



  • @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


  • Lifetime Qt Champion

    You called configure in the same folder without cleaning first ?



  • @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.



  • 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.



  • 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.


  • Lifetime Qt Champion

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

    Did you check the backtrace ?



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

    Did you check the backtrace ?

    It breaks here:

    alt text

    alt text



  • 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).


  • Lifetime Qt Champion

    Did you re-run qmake before building ?



  • @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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.