Skip to content

Build from Linux to Linux Static

Radhi edited this page Feb 3, 2019 · 3 revisions

There are three steps for building static QML app in Linux :

Build Qt statically from source

Static linking is often the easiest way to distribute an application on Linux since it relieves you from the task of distributing the Qt libraries. Unfortunately, Qt doesn't provide static version of the library, so we have to build it from the source. In this tutorial, I'll install the static Qt to /home/radhi/Qt5.12.0.Static. Make sure you've installed g++ in your system.

  1. Download the source code for Qt in the official site, then extract it to your preferred location. In my case, I've extracted it to /home/radhi/Downloads/qt-everywhere-src-5.12.0/.

  2. Open terminal, then cd to source directory :

    cd /home/radhi/Downloads/qt-everywhere-src-5.12.0
    
  3. Inside the source directory, run the configuration :

    ./configure \
    -prefix "/home/radhi/Qt5.12.0.Static" \
    -opensource \
    -static \
    -release \
    -optimize-size \
    -qt-doubleconversion \
    -no-icu \
    -qt-pcre \
    -qt-zlib \
    -qt-freetype \
    -qt-harfbuzz \
    -qt-xcb \
    -qt-libpng \
    -qt-libjpeg \
    -make libs \
    -nomake tools \
    -nomake examples \
    -nomake tests \
    -skip qtwebengine
    
    • -prefix is the location for installing static Qt.
    • -opensource means we are using open source version of Qt.
    • -static means we are building Qt statically.
    • -release means Qt will be build without support for debugging.
    • -optimize-size means Qt will optimize release builds for executable size instead of build speed.
    • -qt-doubleconversion means Qt will use its own double conversion library instead of the one that owned by system.
    • -no-icu means Qt will be build without support for ICU, which is fine because we won't use the WebEngine module of Qt.
    • -qt-pcre until -qt-libjpeg means we will use Qt's libraries instead of systems.
    • -make libs means Qt will build its libs.
    • -nomake tools until -nomake tests means Qt will not build the tools, example and the tests.
    • -skip qtwebengine because I won't use it.
  4. Wait until configuration finished, then run make -j4 to build Qt statically. Replace the 4 with number of CPU core that available on your system. It might take a long time, depending on your system. The build process might take a long time. In my case, it took almost 3 hours, so you might want to sleep or do anything else while it building.

  5. Once the build process finished, install it using make install.

  6. Once finished, static version of Qt will be installed in the specified prefix, in this case is /home/radhi/Qt5.12.0.Static.

Set up new profile

Once static Qt installed, we need to create a new profile for qamel. In this tutorial, we will create a profile named linux_static by running :

qamel profile setup linux_static

The command above will ask you to submit the information about your OS, build mode, and path to the static Qt that you've installed before. Once finished, it should look like this :

Thanks for using qamel, QML's binding for Go.

Please specify the target OS for this profile. Possible values are "windows", "linux" and "darwin". 
Keep it empty to use your system OS.

Target OS (default linux) : linux

Please specify the target architecture for this profile. Possible values are "386" and "amd64".
Keep it empty to use your system architecture.

Target arch (default amd64) : amd64

Please specify whether this profile used to build static or shared app.

Use static mode (y/n, default n) : y

Please specify the *full path* to your Qt's tools directory.
This might be different depending on your platform or your target. For example, in Linux with Qt 5.11.1, the tools are located in $HOME/Qt5.11.1/5.11.1/gcc_64/bin/

Qt tools dir : /home/radhi/Qt5.12.0-static/bin/
qmake        : found
moc          : found
rcc          : found

Please specify the *full path* to your compiler.
Keep it empty to use the default compiler on your system.

C compiler (default gcc)   : gcc
C++ compiler (default g++) : g++

Generating some code for binding...done
Saving profile linux_static...done

Setup finished.
Now you can get started on your own QML app.

Build the app

Once static Qt installed and the profile created, the last thing to do is to build our qamel app using the static Qt. To do that, run qamel build using profile that we've created before :

qamel build -p linux_static