PDA

View Full Version : How to statically compile my project with Qt on Linux



pellyhawk
29th June 2012, 14:57
I would like to statically compile my project with Qt on Linux, how should I do?

I used the command:

./configure -static -release -qt-zlib -qt-gif -qt-libpng -qt-libmng -qt-libjpeg -nomake demos -nomake examples -qt-sql-sqlite -prefix /usr/local/Trolltech/Qt-4.7.3-static
make
make install

then what should I do? Thanks!

high_flyer
29th June 2012, 15:42
I used the command:
And?
What are the results?

This command should build a static Qt lib, which you need if you want to build your application with Qt statically.
Now you need to build your project and link to the static Qt lib which you just built with above command.

pellyhawk
29th June 2012, 18:38
My project (I compiled it dynamically successfully before) is located at /mnt/hgfs/VBox_Shared/SeaTools, then:



cd /mnt/hgfs/VBox_Shared/SeaTools
make


but cannot continue. Then add
QMAKE_LFLAGS += -static
after

TEMPLATE = app
TARGET =
DEPENDPATH += . debug include release translations
INCLUDEPATH += . include
QT += network

I got error results:
mike@mike-desktop:/mnt/hgfs/VBox_Shared/SeaTools$ make
/usr/bin/uic-qt4 calccrcdialog.ui -o ui_calccrcdialog.h
/usr/bin/uic-qt4 chooseareadialog.ui -o ui_chooseareadialog.h
/usr/bin/uic-qt4 choosedatadialog.ui -o ui_choosedatadialog.h
/usr/bin/uic-qt4 choosezftabdialog.ui -o ui_choosezftabdialog.h
/usr/bin/uic-qt4 comsetdialog.ui -o ui_comsetdialog.h
/usr/bin/uic-qt4 downloaddialog.ui -o ui_downloaddialog.h
/usr/bin/uic-qt4 grouptestdialog.ui -o ui_grouptestdialog.h
/usr/bin/uic-qt4 inputdialog.ui -o ui_inputdialog.h
/usr/bin/uic-qt4 logindialog.ui -o ui_logindialog.h
/usr/bin/uic-qt4 mainwindow.ui -o ui_mainwindow.h
/usr/bin/uic-qt4 settimedialog.ui -o ui_settimedialog.h
/usr/bin/uic-qt4 transfiledialog.ui -o ui_transfiledialog.h
/usr/bin/uic-qt4 transfiledialog_js.ui -o ui_transfiledialog_js.h
/usr/bin/uic-qt4 uploaddialog.ui -o ui_uploaddialog.h
/usr/bin/uic-qt4 usrmanagedialog.ui -o ui_usrmanagedialog.h
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -Iinclude -I. -I. -o addgrptabledelegate.o addgrptabledelegate.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -Iinclude -I. -I. -o calccrcdialog.o calccrcdialog.cpp
......
......
......
moc_inputtabledelegate.o moc_jctabledelegate.o moc_logindialog.o moc_mainwindow.o moc_myclient.o moc_myfileprocess.o moc_nodetabledelegate.o moc_othertabledelegate.o moc_pointtabledelegate.o moc_porttabledelegate.o moc_settimedialog.o moc_supporttabledelegate.o moc_transfileclient.o moc_transfileclient_js.o moc_transfiledelegate.o moc_transfiledelegate_js.o moc_transfiledialog.o moc_transfiledialog_js.o moc_transmittabledelegate.o moc_uploaddialog.o moc_usrmanagedialog.o moc_zftabledelegate.o qrc_seatools.o -L/usr/lib -lQtGui -lQtNetwork -lQtCore -lpthread
/usr/bin/ld: cannot find -lQtGui
collect2: ld returned 1 exit status
make: *** [SeaTools] Error 1
mike@mike-desktop:/mnt/hgfs/VBox_Shared/SeaTools$


Or I modified Makefile by:
CXXFLAGS = -static -pipe -Wall -W -O2 -fomit-frame-pointer -pipe -march=i586 -mcpu=pentiumpro -DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT and got similar error results.

amleto
29th June 2012, 18:55
what is the location of yuor static qt libs?

pellyhawk
30th June 2012, 12:46
/usr/locat/Trolltech/Qt-4.7.3-static/lib

I add

export QTDIR=/usr/local/Trolltech/Qt-4.7.3-static
export PATH=$QTDIR/bin:$PATH
export MANPATH=$QTDIR/man:$MANPATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
at the bottom of /etc/profile

/usr/locat/Trolltech/Qt-4.7.3-static/lib

I add

export QTDIR=/usr/local/Trolltech/Qt-4.7.3-static
export PATH=$QTDIR/bin:$PATH
export MANPATH=$QTDIR/man:$MANPATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
at the bottom of /etc/profile

high_flyer
2nd July 2012, 09:12
you are building a debug project and linking to a release Qt lib.

pellyhawk
2nd July 2012, 11:36
you are building a debug project and linking to a release Qt lib.

How did you know it? I am a newbie. And what shall I do next? Thanks.

wysota
2nd July 2012, 11:45
/usr/locat/Trolltech/Qt-4.7.3-static/lib

I add

export QTDIR=/usr/local/Trolltech/Qt-4.7.3-static
export PATH=$QTDIR/bin:$PATH
export MANPATH=$QTDIR/man:$MANPATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
at the bottom of /etc/profile

/usr/locat/Trolltech/Qt-4.7.3-static/lib

I add

export QTDIR=/usr/local/Trolltech/Qt-4.7.3-static
export PATH=$QTDIR/bin:$PATH
export MANPATH=$QTDIR/man:$MANPATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
at the bottom of /etc/profile

You can see in your compilation log that you are using Qt located in /usr/ and not in /usr/local/Trolltech/Qt-4.7.3-static.

What does qmake -v return?

high_flyer
2nd July 2012, 11:53
How did you know it?
That is what you configured.
When building Qt:

./configure -static -release

Actually I am not sure if your project build is just debug both debug and release.
Try putting this in your projects *.pro file:
CONFIG = release

In addition, I see your lib search path for your porject is not correct:
-L/usr/lib
Try adding
LIBS += -L/usr/local/Trolltech/Qt-4.7.3-static/lib

pellyhawk
2nd July 2012, 14:20
You can see in your compilation log that you are using Qt located in /usr/ and not in /usr/local/Trolltech/Qt-4.7.3-static.

What does qmake -v return?
mike@mike-desktop:/lib$ qmake -v
QMake version 2.01a
Using Qt version 4.7.3 in /usr/local/Trolltech/Qt-4.7.3-static/lib

Is this is the location of static Qt lib?

wysota
2nd July 2012, 14:26
Good. So now cd to the directory containing your project, run qmake and only then run make.

pellyhawk
2nd July 2012, 14:49
That is what you configured.
When building Qt:


Actually I am not sure if your project build is just debug both debug and release.
Try putting this in your projects *.pro file:
CONFIG = release

In addition, I see your lib search path for your porject is not correct:
-L/usr/lib
Try adding
LIBS += -L/usr/local/Trolltech/Qt-4.7.3-static/lib

Yes, I add "CONFIG = release" at .pro file.

TEMPLATE = app
TARGET =
DEPENDPATH += . debug include release translations
INCLUDEPATH += . include
QT += network
CONFIG += static
Do I add it right?

And I add "LIBS += -L/usr/local/Trolltech/Qt-4.7.3-static/lib" at .pro or Makefile?

You told me that "lib search path for your porject is not correct". Do found it by "g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -Iinclude -I. -I. -o addgrptabledelegate.o addgrptabledelegate.cpp" (SHARED???)

Thanks.