[Qt-interest] static linking
Linda Maria
linda.maria.bjork at gmail.com
Tue May 26 16:39:00 CEST 2009
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 lib*somename*.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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090526/e3c16a9b/attachment.html
More information about the Qt-interest-old
mailing list