S
S
Sergey782013-02-27 12:26:00
Qt
Sergey78, 2013-02-27 12:26:00

Building QT 5.0.1 static

Good afternoon.
I wrote a small application in QT, I want to make it available not only on my laptop, but also for everyone else. I have Windows 7 64 bit, I would like the application to work on XP 32 bit.
In general, what I did and what I achieved:
1. To begin with, I downloaded “Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)” from the qt-project.org/downloads page. It is the 5th version that I don’t need, but for it there is an “everything inside” package, with a compiler and everything-everything-everything.
2. When installing, I installed all the components, including Src.

Everything is installed in D: \ Qt, as a result I have the following folder structure:
In D: \ QT, the QT5.0.1 folder, in which the folders are:
5.0.1
Licenses
Tools

Inside the 5.0.1 folders are mingw47_32 and Src.
The path to g++.exe and mingw32-make.exe is D:\Qt\Qt5.0.1\Tools\MinGW\bin

At this point, I verified that my application compiles and runs. True only from Qt Creator. An attempt to transfer it was unsuccessful.
I copied to it all the libraries that Dependency Walker said about, but it still does not start. Well, that's not the point, dragging 150 kb of libraries to 40 mb with an application is not a very good idea. I decided to build static.

For some reason, the paths that are written about in the documentation and in articles on Habré look completely different for me. Perhaps due to the fact that the version of Qt is not 4.8, but 5.0
In general, I found configure.exe in D:\Qt\Qt5.0.1\5.0.1\Src\qtbase
qmake.conf I corrected it in two places, in D: \Qt\Qt5.0.1\5.0.1\Src\qtbase\mkspecs\win32-g++ and in D:\Qt\Qt5.0.1\5.0.1\mingw47_32\mkspecs\win32-g++
In both files, I replaced the “QMAKE_LFLAGS = ” option with “QMAKE_LFLAGS += -static”
After that, I installed Perl and in the D:\Qt\Qt5.0.1\5.0.1\Src\qtbase directory I performed first:

SET QTDIR=D:\ Qt\Qt5.0.1\5.0.1\
SET PATH=D:\Qt\Qt5.0.1\5.0.1\mingw47_32\bin;D:\Qt\Qt5.0.1\Tools\MinGW\bin;D:\Perl\ perl\bin;%PATH%

configure -opensource -release -nomake examples -nomake demos -nomake tools -nomake translations -nomake docs -no-rtti -no-openssl -no-opengl -static -platform win32-g++

And then "mingw32 -make»

It compiled in 15-20 minutes, it did not give any errors.

However, now, when I try to build the application from Qt Creator, I get errors like
"skipping incompatible D:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib\libQt5Gui.a when searching for -lQt5Gui"
"cannot find -lQt5Gui"

What I want to achieve:
By and large, I don't need QT Creator and so on (I write and test the application on Linux, and users on windows). I would like to have a minimum for a static build of the application as in Linux - I ran “make clean && qmake -project && qmake && make” in the folder and got a ready .exe
Well, understand what I did wrong and why the compilation broke.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Thekondr, 2013-02-27
@Thekondr

According to my experience, it is better to specify the path to qtbase in QTDIR, as well as the path to qtbase \ bin in PATH, although if everything compiled without problems for you, then this is probably not the case.
Most likely there is a problem in the platform, for example, a 32-bit version of the library was compiled, but your application is 64-bit, or something like that.
However, you should take into account that according to the LGPL license, when using the static version of the library, all program source codes must be made available to the public.
Regarding the first problem with the dynamic version: Dependency Walker does not (because it cannot) take into account the need to load Qt plugins at runtime. Look in the 5.0.1 folder for the plugins folder and copy its contents(and not itself) to the directory to the exe file. In rare cases, the same thing needs to be done with the imports folder.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question