问题
I am quite new to Qt programming, and i tried long to understand how linking the libraries work. I need to distribute a small program - 1000 lines or so - that i developed to a few people.
I built statically Qt because I need a static build, and now my programs size increased drammatically.
I only use Qpushbuttons, Qlinedits, Qlabels, and a few more things and I ended up with a compiled program of over 160Mb, while just a few MB would be reasonable.
I assume it included unwanted libraries and classes (only explanation).
How can I keep the size something acceptable with a static build?
I'm running linux 64bit and need to compile as such and for it.
thanks
回答1:
I'm assuming that you are doing a project build in debug mode. I propose to build application in the release mode. The size of the output file will decrease dramatically.
回答2:
That's right, you need to build qt in release mode. I have been building qt for a couple of years. The best and simplest method I've done is (both Linux and Windows):
Install Qt sources. (last available)
Install Python 2.7.X to build QML (last available)
Open terminal and execute configure command in src directory:
LINUX:./configure -prefix "/somePath/Qt511Static" -static -release -opensource -confirm-license -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -fontconfig -qt-xcb -opengl desktop -sql-sqlite -make libs -nomake tools -nomake examples -nomake tests -skip qtwebengine
WINDOWS:configure -prefix "/somePath/Qt511Static" -static -static-runtime -release -opensource -confirm-license -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -sql-sqlite -make libs -nomake tools -nomake examples -nomake tests -skip qtwebengine
Build:
make -k -jN
(Linux) ormingw32-make -k -jN
(Windows)Install:
make -k install
(Linux) ormingw32-make -k -jN
(Windows)Set the kit in Qt Creator.
Goto Tools -> Options -> Build & Run -> Qt Versions and search your newly installed qmake executable. Apply changes. Then goto Kits and create a new kit and set on it the newly qt version.
NOTE: Use flag -release
to make smaller apps (~20 MB).
NOTE: Use flag -jN
to build faster (using multiples jobs). Replace N
with the number of cores of your processors.
来源:https://stackoverflow.com/questions/25426895/qt-static-build-impossible-size