therecipe / qt

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
GNU Lesser General Public License v3.0
10.42k stars 744 forks source link

Using static Qt libs in therecipe/qt #982

Open stdevCrow opened 5 years ago

stdevCrow commented 5 years ago

The following issue has two targets:

1. Static compilation under Linux

2. Using the static kit with therecipe/qt


Sadly, static compilation of Qt is not so well documented, I think, so a wiki page can be useful on this topic.

1. Static compilation under Linux

I have success many times on creating static kits under Windows, but sadly not under Linux.

My Linux configure command:

./configure -prefix "/somePath/Qt5Static" -static -release -opensource -confirm-license -qt-pcre -qt-zlib -qt-freetype -qt-xcb -qt-libpng -qt-libjpeg -qt-sqlite -nomake tools -nomake examples -nomake tests -skip webengine -silent

So there are a few questions:

  1. It is ok to use the 3rd party libs bundled with Qt instead of the system ones?
  2. What dependencies do you usually install (besides the ones mentioned in the doc) before configure?
  3. What is your configure command?

2. Using the static kit with therecipe/qt

After building Qt statically, how can we use it with therecipe/qt?


The main purpose of building Qt statically in this case is because I am making a custom, simple, minimalist and lightweight installer framework because the QtIFW do not allows offline updates and making a custom UI (using Qt Quick Controls 2 module) is very hard. And an installer must be statically compiled.

therecipe commented 4 years ago

Hey

It is ok to use the 3rd party libs bundled with Qt instead of the system ones?

Yeah, I think it's okay. (And the binding doesn't really care which ones you use anyway)

What dependencies do you usually install (besides the ones mentioned in the doc) before configure? What is your configure command?

The are quit a few deps needed for static builds of Qt under linux, especially if you want to get it working inside a docker container. But I created a docker image some time ago, which you could use to deploy statically compiled applications for linux. To do so just run qtdeploy -docker build linux_static If you want to see how the image was made (and/or create your own custom docker image), then take a look at these two images:

This one builds a static Qt version: https://github.com/therecipe/qt/blob/master/internal/docker/linux/Dockerfile.static_base

And this one sets up the binding inside a docker container, so you can use the image for docker deployments with qtdeploy -docker ...: https://github.com/therecipe/qt/blob/master/internal/docker/linux/Dockerfile.static

After building Qt statically, how can we use it with therecipe/qt?

You usually only need to export QT_QMAKE_DIR=path/to/static/qmake/dir and QT_STATIC=true. But I only tested this on linux and macOS. For static windows builds I usually just use MXE's static Qt version and cross compile from linux to windows. (by using qtdeploy -docker build windows_64_static) I can take a look and see what changes would be needed to get static windows build working on windows though.

Btw, you can find the configure command to get static macOS builds of Qt working here

stdevCrow commented 4 years ago

Thank u! I will try that.

LateusBetelgeuse commented 4 years ago

BTW this what I do to build Qt statically on Windows. It can be improved (I will improve it), but it works 100% because I installed a Unix env and checked the dependences with ldd, and the output was:

ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x7ffc685f0000)
??? => ??? (0x77400000)
wow64.dll => /c/Windows/System32/wow64.dll (0x7ffc658d0000)
wow64win.dll => /c/Windows/System32/wow64win.dll (0x7ffc68540000)
  1. Install DirectX SDK.
    • Add it to path, and also the Include, Libs and Utilities/bin folders (select the target architecture, x86 or x64). NOTE: Install DirectX SDK is not a strict requirement, you can build Qt without it, but ANGLE will not be build, which is not a problem if you use OpenGL, (which is the default, anyway).
  2. Install Python.
    • Add to path the installation folder and also add the folder Scripts.
  3. Install ActivePerl.
    • Add the folders perl/bin, c/bin, and perl/site/bin.
  4. Bootstrap qmake: $ configure -prefix "X:/somePath/QtStatic" -static -static-runtime -release -opensource -confirm-license -nomake tools -nomake examples -nomake tests -skip qtwebengine -silent
  5. Compile Qt: $ mingw32-make -k -j4
  6. Install Qt: $ mingw32-make -k install
therecipe commented 4 years ago

Thanks, I will try to build it on Windows and see what needs to be done once I find some time.