0

How to build a static project in QT? I would like to see step by step instructions. My version qt 5.12.2 OS: Ubuntu 18.04

1
  • 1
    What's a "static project"? Commented May 20, 2019 at 2:17

1 Answer 1

1

You need to build Qt itself statically. Instructions:

https://doc.qt.io/qt-5/linux-building.html

To do a static build, pass the -static flag to ./configure. You might want to install this in your home directory instead of system wide. In that case, also pass something like -prefix $HOME/custom_qt/5.12.3 so that this Qt build will be installed in your home directory when you do make install.

Building is going to take a long time, so make sure to use make -jN to build it (replace N with the amount of threads/cores your CPU has.) It will still take a long time even with that, so you should probably disable Qt modules you don't need (like the webkit module). If you downloaded the complete source package of Qt (like https://download.qt.io/official_releases/qt/5.12/5.12.3/single/qt-everywhere-src-5.12.3.tar.xz), then you should simply delete the subdirectories of the modules you don't need before calling ./configure.

Once you've built and installed it successfully, you need to build your application using this version of Qt. If your application uses qmake, then use ~/custom_qt/5.12.3/bin/qmake to configure and build it.


Alternative to static building
Note that instead of using static linking, you can instead use normal dynamic linking but package your application as an AppImage using the linuxdeployqt tool. More info on AppImage:

https://appimage.org

Sign up to request clarification or add additional context in comments.

4 Comments

I execute the command: /home/user/Downloads/linuxdeployqt-6-x86_64.AppImage /home/user/projects/qtpro/build-mycpptest-Desktop_Qt_5_12_3_GCC_64bit-Release/mycpptest -unsupported-allow-new-glibc -appimage
Writes me: fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). NOTE: Using the output of 'git rev-parse --short HEAD' as the version: Please set the $VERSION environment variable if this is not intended Categories entry not found in desktop file .desktop file is missing a Categories= key
Success! It was necessary to register in default.desktop Categories = GTK; GNOME; Thank you very much!
@AngelPensive Categories should be one of these: specifications.freedesktop.org/menu-spec/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.