1

http://qt-project.org/doc/qt-4.8/deployment-windows.html say:

Before we can build our application we must make sure that Qt is built statically. To do this, go to a command prompt and type the following:

cd C:\path\to\Qt
configure -static <any other options you need>

doing so result in:

'configure' is not recognized as an internal or external command,
operable program or batch file.

is there any step by step guide explaining how can I configure my QT project so that it produces statically linked binaries?

Also, this guide seem to expect user to have full msvc compiler, I am using MinGW so I have no setenv batches

Petr
  • 13,747
  • 20
  • 89
  • 144
  • I built `Qt` from source via `Cygwin` with `MinGW`. `configure` was available there. – Adri C.S. Sep 24 '13 at 07:32
  • I downloaded precompiled qt installation .msi file... so should I try doing this in msys window? – Petr Sep 24 '13 at 07:38
  • Is that precompiled `Qt` valid for `MinGW`? For `MinGW` I had to build `Qt` from scratch. I installed the `Cygwin` environment and the `configure` tool was available there. I suppose it will be available as well for `msys`, but I'm not sure. – Adri C.S. Sep 24 '13 at 07:43
  • If resort to built it from scratch I can pass you a link from Qt Project where they explain how to do this. Oh! I built `Qt 4.8.1`, for the new `Qt 5` I don't know if the process will be the same. – Adri C.S. Sep 24 '13 at 07:45
  • Just to make sure you ran: ``./configure`` in cygwin bash, the path does not include the current working directory, so a heading **./** is required. Do you need to have QT compiled statically into your app? This requires you to open up the sources to your app or buy a commercial license if you want to redistribute it. – Sebastian Lange Sep 24 '13 at 07:56
  • but I do compile my application using mingw... I just want to know what I need to do so that produced .exe file can be ran standalone without having to copy all these .dll files together with it – Petr Sep 24 '13 at 08:25
  • 1
    You need to build Qt with MinGW as well. See [this](http://stackoverflow.com/questions/2472924/linking-to-msvc-dll-from-mingw) (MinGW has some tools to convert from VS dll to a MinGW one, that might be helpful). You have to donwload Qt sources and build them from scratch using your MinGW compiler – Adri C.S. Sep 24 '13 at 08:47
  • For not having to copy all those .dll files you will have to recompile Qt-sources as static (as already mentioned by @Adri C.S) and you need to release your application under GPL/LGPL including the sources or get a commercial license. This is part of the dual licensing digia introduced to Qt (given you want to redistribute your application at all, if its just your own personal use nobody gonna mind) – Sebastian Lange Sep 24 '13 at 09:14
  • @SebastianLange: It is not true that you have to release commercial code as GPL/LGPL in order to use LGPL'd Qt. All you need is to allow your users to re-link with their version of Qt. It's normally done by distributing a static library (`.a`/`.lib`) containing your application's object code. Then anyone can relink it either statically with Qt. – Kuba hasn't forgotten Monica Sep 24 '13 at 11:00
  • @KubaOber: For statically linking your application with Qt (this makes the library included in the application) and therefor "hiding" Qt's existance, you need to relaese your app as GPL/LGPL (which makes is open source) or get a commercial license from digia. As far as i can tell, you cannot just relink a statically included Qt, therefor you need a dynamically included or from the platform provided library. So **static linking** Qt in an application only is possible if you LGPL your application or buy a commercial license. Just formal: A library is no application. – Sebastian Lange Sep 24 '13 at 11:59
  • @KubaOber: If you provide a static library which then can be linked with their own static Qt to create a statically linked application, it should be no problem. But as soon as you statically include Qt... ra. – Sebastian Lange Sep 24 '13 at 12:02

1 Answers1

0

Make sure you've downloaded the .zip variant of Qt sources (4.8.5). The .tar.gz one is missing configure.exe, at least for Qt 5.

It should work then.

Note that there are two levels of "staticness":

  1. Qt itself as a static library.

  2. Qt's (and your application's) dependency on the C/C++ runtime.

Since you likely want both, you must coerce Qt itself to statically link with the C/C++ runtime library. I've not done it for mingw yet, but it will require changing the relevant qmake.conf. This change will propagate to the code you build using such tweaked Qt, so your application will statically link to both Qt and to the C/C++ runtime.

Using MSVC2012 and link time code generation, after UPX-ing the executable, the size is ~3mb for a small application using the gui and network modules. Just to give an idea of how big it will be. It'll likely be larger when using mingw.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313