[Qt-interest] static linking

Malyushytsky, Alex alex at wai.com
Tue Jun 2 05:06:11 CEST 2009


Sorry for later correction:

>>  QT4 can be built only with Static CRTs, even if you build it statically .

Should be read as

.... QT4 can be built only with Dynamic CRTs, even if you build it statically .


From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Malyushytsky, Alex
Sent: Friday, May 29, 2009 7:20 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] static linking

On the Windows you have to make sure that QT, all your static libraries,
and everything else linked to your application using the same C runtime libraries (CRT).
I am not sure about other compilers but if you are using any of Microsoft VC,
QT4 can be built only with Static CRTs, even if you build it statically .

So you have no choice, but build your static libraries with Dynamic CRTs.

As soon you done it, and all static/dynamic libraries are linked to the same (don't mix debug and release either) dynamic CRT libs, you should have no problem to build anything.


Best regards,
Alex




From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Linda Maria
Sent: Tuesday, May 26, 2009 7:39 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] static linking

Hi all

I want to statically link my own libs, however, still dynamically linking against Qt. When I do this I get undefined reference error. Well, it is clear that the compiler is not finding my libsomename.a file, however, if I compile my library dynamically the compiler has no problem finding somename.dll file.

-I am working with QT 4.5
-I am working on Windows with Qt Creator

Example .pro files are as folow:

lib pro file:
QT -= gui

TARGET = hello_world_lib

TEMPLATE = lib

CONFIG += staticlib

DEFINES += HELLO_WORLD_LIB_LIBRARY

SOURCES += helloworld.cpp

HEADERS += helloworld.h\

hello_world_lib_global.h



app pro file:

TARGET = hello_world

TEMPLATE = app

INCLUDEPATH += ..\hello_world_lib

CONFIG += static

LIBS += -L..\hello_world_lib\debug -lhello_world_lib

TARGETDEPS += ..\hello_world_lib\debug\libhello_world_lib.a

SOURCES += main.cpp \

mainwindow.cpp \

helloworlddialog.cpp

HEADERS += mainwindow.h \

helloworlddialog.h

FORMS += mainwindow.ui \

helloworlddialog.ui \

helloworlddialog.ui



ld output is:

debug/mainwindow.o(.text+0x1bd): In function `ZN10HelloWorld10MainWindowC2EP7QWidget':

C:/Documents and Settings/es030699/My Documents/Qt/hello_world/mainwindow.cpp:15: undefined reference to `_imp___ZN13HelloWorldLib10HelloWorld10getMessageEv'

debug/mainwindow.o(.text+0x3cb): In function `ZN10HelloWorld10MainWindowC1EP7QWidget':

C:/Documents and Settings/es030699/My Documents/Qt/hello_world/mainwindow.cpp:15: undefined reference to `_imp___ZN13HelloWorldLib10HelloWorld10getMessageEv'

collect2: ld returned 1 exit status

mingw32-make.exe[1]: *** [debug\hello_world.exe] Error 1

C:\MinGW\bin\mingw32-make.exe: *** [debug] Error 2

Exited with code 2.

Error while building project hello_world

When executing build step 'Make'



Notice the line

CONFIG += staticlib

in the lib pro file tellst the compiler to create libhello_world_lib.a to statically link agains, and not to create hello_world_lib.dll. I thought the compiler should automatically find out that only a static library is provided and link against it.



Can someone please help me with this?

Thanks,

Linda Maria


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090601/8c7f5a5a/attachment.html 


More information about the Qt-interest-old mailing list