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:
-
Install QT with these components, to default path:
-
Download jom and unzip it to
C:\Qt\Jom\jom.exe
-
Create a folder
C:\Qt\5.9.3\static
next to the defaultC:\Qt\5.9.3\Src
-
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%
- 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
- Add the static version to Qt Creator
- 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:
- What is an installed prefix build?
- Why doesn't the debug build work?
- Why is the release build 15MB huge for an empty window?
-
-
Hi,
- The usual way to build and install Qt is to use an out of source build and call
nmake/mingw32-make install
when done. - Don't know, not enough details
- 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.
- The usual way to build and install Qt is to use an out of source build and call
-
@SGaist said in Creating a static linked exe - what did I miss?:
Hi,
- The usual way to build and install Qt is to use an out of source build and call
nmake/mingw32-make install
when done. - Don't know, not enough details
- 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
- The usual way to build and install Qt is to use an out of source build and call
-
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.
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:
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.
-
No it's not, it's only used for QML.
Did you check the backtrace ?
-
I just noticed that this
testapp_plugin_import.cpp
loads a whole bunch of stuff that I don't use.Could this be a reason for the exe file being huge?
I tried disabling them in the .pro file usingQTPLUGIN -= qgif
, but it changed nothing (this file still looks the same after rebuild). -
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