📜 ⬆️ ⬇️

Qt - static linking library under Windows

Good day to all, I decided to write this article especially for those who want or still want his program written with the help of Qt under Windows to work even where about Qt and have not heard, there is an article on Habré where this problem is solved by accompanying our .exe libraries from skazkin . I myself have been looking for a solution to this issue for a very long time, but they talked about it almost everywhere, but nothing effective was possible. As a result, collecting and analyzing everything that came to me from different sources, I finally did it and if anyone else is interested in asking everyone under

A little bit about yourself. My axis is Windows 7 (although XP was all, too), Qt 4.7.4 libraries (if you have a + - a couple of versions is fine), Qtcreator 2.3.1 + MinGw compiler. First I put Qt Creator, which can be downloaded from the official site already with the MinGW compiler (and not only that, but everything else), then the library.
Getting to the most interesting, let's say that everything is already installed or delivered:
1. Find the directory where we installed our library, something like C: \ Qt \ 4. *. * \ , Or rather in C: \ Qt \ 4. *. * \ Mkspecs \ win32-g ++ (by the way, never use Cyrillic in the name of the path to any Qt files, just do not do it) and we find there config-file qmake.conf , open it with a notepad and add a line
QMAKE_LFLAGS += -static , I set it to the other flags.

2. Now create a .bat file, and no matter where with something like the following content. Where the first two lines will be:
SET QTDIR=C:\Qt\4.7.4
SET PATH=C:\Qt\qtcreator-2.3.1\mingw\bin; C:\Qt\4.7.4\bin;%PATH%

It is important, as you understand, to change directories to your own, unless of course they match. Further:
configure -opensource -release ^
-nomake examples -nomake demos -nomake tools ^
-nomake translations -nomake docs ^
-no-exceptions -no-stl -no-rtti ^
-no-qt3support -no-scripttools -no-openssl -no-opengl ^
-no-dsp -no-webkit -no-phonon ^
-no-style-motif -no-style-cde -no-style-cleanlooks ^
-no-style-plastique ^
-no-script -no-scripttools -no-declarative ^
-static -platform win32-g++

mingw32-make

The note above lists the libraries that will be excluded from the static build, so if you like me, for example, need Qt3 support, then remove -no-qt3support , and so everything you need, or add what you don’t need, but be careful.

3. Everything. We save and run our .bat and go to drink coffee, libraries are now going without us.
')
After all that has been done, our projects will be collected in release mode, completely static and code as soon as possible, discarded on a USB flash drive and carry to show all this to our friend!

Special thanks for the guidance and support michurin
And do not judge strictly, I hope this will help someone, because he himself has been looking for it for a very, very long time ...

Source: https://habr.com/ru/post/137233/


All Articles