Qt static build - impossible size

让人想犯罪 __ 提交于 2019-12-11 08:17:14

问题


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):

  1. Install Qt sources. (last available)

  2. Install Python 2.7.X to build QML (last available)

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

  1. Build: make -k -jN (Linux) or mingw32-make -k -jN (Windows)

  2. Install: make -k install (Linux) or mingw32-make -k -jN (Windows)

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!