[Qt-interest] static linking

Linda Maria linda.maria.bjork at gmail.com
Thu May 28 11:27:53 CEST 2009


> Linda Maria wrote:
> > 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
> >
>
> I do what you are trying to do routinely on both Windows and Linux.
> However, in my library .pro files, I have
> CONFIG += static
> not staticlib.
> You might look at the Makefiles that are generated by qmake and see what
> they look like.
>
>
> Hi and thanks for the reply

I am still having problem with static linking. In the moment I am using
dynamic linking (not what I want). The output from the compiler is as follow
and the makefile is attached.

Please you guys that are experts on Qt, give me a hand on this.
Thanks,
Linda Maria

Running build steps for project hello_world...

Starting: C:/Qt/4.5.1/bin/qmake.exe C:/Documents and Settings/es030699/My
Documents/Qt/hello_world/hello_world.pro -spec win32-g++ -r

Exited with code 0.

Starting: C:/MinGW/bin/mingw32-make.exe -w

C:\MinGW\bin\mingw32-make.exe: Entering directory `C:/Documents and
Settings/es030699/My Documents/Qt/hello_world'

C:/MinGW/bin/mingw32-make.exe -f Makefile.Debug

Makefile.Debug:126: warning: overriding commands for target
`ui_helloworlddialog.h'

Makefile.Debug:123: warning: ignoring old commands for target
`ui_helloworlddialog.h'

mingw32-make.exe[1]: Entering directory `C:/Documents and
Settings/es030699/My Documents/Qt/hello_world'

g++ -enable-stdcall-fixup -Wl,-enable-auto-import
-Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o
debug\hello_world.exe debug/main.o debug/mainwindow.o
debug/helloworlddialog.o debug/moc_mainwindow.o debug/moc_helloworlddialog.o
-L"c:\Qt\4.5.1\lib" -lmingw32 -lqtmaind -L..\hello_world_lib\debug
-lhello_world_lib -lQtGuid4 -lQtCored4

mingw32-make.exe[1]: Leaving directory `C:/Documents and
Settings/es030699/My Documents/Qt/hello_world'

C:\MinGW\bin\mingw32-make.exe: Leaving directory `C:/Documents and
Settings/es030699/My Documents/Qt/hello_world'

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'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090528/ef559710/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile.Debug
Type: application/octet-stream
Size: 6725 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090528/ef559710/attachment.obj 


More information about the Qt-interest-old mailing list