[Qt-interest] static linking
Eckhard Jokisch
e.jokisch at orange-moon.de
Thu May 28 12:57:33 CEST 2009
You will have to try it ;)
And pls. use the "reply to all" or "reply to list" function when responding ;)
Regards
Eckhard
On Thursday 28 May 2009 12:25:50 Oliver Demetz wrote:
> Hi,
> thanks for this clarifying answer!
> Next question: is it possible to build
> qt for both, static and dynamic linkage
> and to be able to simply choose the
> wanted configuration afterwards?
> In the best case, it would be nice to
> have both configurations (or libs) in
> the same directory and to not have to
> alter the paths and so on.
>
> Regards,
> Oliver
>
> Eckhard Jokisch schrieb:
> > The QT-library has to be configured in a way that it can be lnked static.
> > AFAIK it's ./confgure -static
> > This gives also different names for the libraries.
> > Of course you have to compile and install QT after that ./configure
> > -static
> >
> >
> > Then you have to select the correct QT-version also in QT-Creator (if
> > you use that ) and rebuild all.
> >
> >
> > Cheers
> > Eckhard
> >
> > On Thursday 28 May 2009 11:37:08 Oliver Demetz wrote:
> > > Hi,
> > >
> > > I'm not a 100% sure about that, but
> > > as fas as I know you have to compile
> > > the qt library with special settings
> > > if you want to link your program
> > > statically against it.
> > >
> > > I would also be interested in details
> > > on that.
> > >
> > > Best regards,
> > > Oliver
> > >
> > > Linda Maria schrieb:
> > > > 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
> > > > <http://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'
> >
> > ------------------------------------------------------------------------
> >
> > > > _______________________________________________
> > > > Qt-interest mailing list
> > > > Qt-interest at trolltech.com
> > > > http://lists.trolltech.com/mailman/listinfo/qt-interest
> > >
> > > _______________________________________________
> > > Qt-interest mailing list
> > > Qt-interest at trolltech.com
> > > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090528/e4f03260/attachment.html
More information about the Qt-interest-old
mailing list