Creating a static linked exe - what did I miss?
-
wrote on 5 Dec 2017, 17:09 last edited by Zeblote 12 May 2017, 22:01
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:
-
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
-
wrote on 5 Dec 2017, 21:27 last edited by
@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 ?
-
wrote on 5 Dec 2017, 21:38 last edited by Zeblote 12 May 2017, 21:39
@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.
-
wrote on 5 Dec 2017, 21:46 last edited by Zeblote 12 May 2017, 21:49
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. -
wrote on 5 Dec 2017, 21:54 last edited by
-
No it's not, it's only used for QML.
Did you check the backtrace ?
-
wrote on 5 Dec 2017, 22:04 last edited by
@SGaist said in Creating a static linked exe - what did I miss?:
Did you check the backtrace ?
It breaks here:
-
wrote on 5 Dec 2017, 22:13 last edited by Zeblote 12 May 2017, 22:18
-
Did you re-run qmake before building ?
-
wrote on 5 Dec 2017, 22:25 last edited by Zeblote 12 May 2017, 22:26
@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
7/12