PDA

View Full Version : linking static libraries - standalone exe under windows



mastupristi
15th June 2016, 00:14
Hallo,
I have downloaded windows version of qt 5.5.1 - mingw.
In the directory C:/Qt/5.5/mingw492_32/lib there are a lot of .a files, like libQt5Core.a and libQt5Gui.a, so, according to my opinion, I suppose to have the static lib installed. The dll files are located in C:\Qt\5.5\mingw492_32\bin

I create a new "Qt application Project", and I modify .pro as follows:

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = prova
TEMPLATE = app

QMAKE_LFLAGS += -static # try to link the static library
QMAKE_LFLAGS += -Wl,-Map=prova.map # let's produce the map file

SOURCES += main.cpp\
dialog.cpp

HEADERS += dialog.h

FORMS += dialog.ui


it seems tha all works. The linker command line is:

g++ -static -Wl,-Map=prova.map -Wl,-subsystem,windows -mthreads -o debug\prova.exe debug/main.o debug/dialog.o debug/moc_dialog.o -lmingw32 -LC:/Qt/5.5/mingw492_32/lib -lqtmaind -lshell32 -lQt5Widgetsd -lQt5Guid -lQt5Cored
So it seems to use the right directory, and in the map file there are lines like:

.text 0x00402c40 0x8 C:/Qt/5.5/mingw492_32/lib\libQt5Cored.a(d002900.o)
0x00402c40 QObject::timerEvent(QTimerEvent*)
.text 0x00402c48 0x8 C:/Qt/5.5/mingw492_32/lib\libQt5Cored.a(d002895.o)
0x00402c48 QObject::childEvent(QChildEvent*)
.text 0x00402c50 0x8 C:/Qt/5.5/mingw492_32/lib\libQt5Cored.a(d002902.o)
0x00402c50 QObject::customEvent(QEvent*)


So I thought that the exe was stand alone, but if I try to run it fails because it want libQt5Cored.dll.
Why?
Where am I wrong?

best regards
Max

anda_skoa
15th June 2016, 08:54
You write that you see libQt5Core.a, but do you have libQt5Cored.a?
Maybe the static build is release only?

Cheers,
_

mastupristi
15th June 2016, 23:49
there are both release and debug files:

http://www.qtcentre.org/attachment.php?attachmentid=11984&d=1466030737

And I tried both debug and release build. but both seems to require dll's, so are dynamically linked.

where am i wrong

best regards
Max