PDA

View Full Version : Problem with static linking in Linux



elina
22nd July 2012, 13:16
It's one week that I have tried everything I have found on the Internet about static linking, but everything goes wrong.
So you are my last hope!
I use debian 6 32bit and I have done a project with qt ceator.

From here (http://www.qtcentre.org/wiki/index.php?title=Building_static_Qt_on_Linux) I found these:
"First you have to download the source package from Trolltech and unpack it."
I went here (http://qt.nokia.com/downloads) I downloaded the Qt library tar.gz (228 MB) and I extracted it on desktop.
After
"Qt 4.3.x and Later
• type:"

./configure -static -nomake demos -nomake examples -nomake tools
make"
I typed on a terminal

./configure -static -nomake demos -nomake examples -nomake tools but I couldn't do "make" because there wasn't any Makefile
So I found these (https://www.madsoft.org/2011/10/16/building-qt-for-static-linking-on-linux/) advices and I wrote:

./configure -release -opensource -static -platform linux-g++ -no-fast -no-qt3support -no-phonon -no-phonon-backend -no-declarative-debug -no-ssse3 -no-sse4.1 -no-sse4.2 -no-avx -no-neon -qt-zlib -qt-gif -qt-libpng -no-libmng -qt-libjpeg -openssl-linked -nomake examples -nomake demos -nomake docs -no-nis -no-cups -dbus-linked -no-gtkstyle -no-nas-sound -no-opengl -no-openvg -no-glib
This made a Makefile so next I wrote
"make"
and after 2 hours as root "make install"

1) Have I now static libraries?
How can I see it?

Then a Qt folder created in /usr/local/Trolltech/Qt-4.8.2

I went in my .pro and added

CONFIG += static
LIBS += -L/usr/local/Trolltech/Qt-4.8.2

So, now here (http://doc.qt.nokia.com/4.7-snapshot/deployment-x11.html) says to go to the folder that has my project and write:

make clean
PATH=/usr/local/Trolltech/Qt-4.8.2/bin:$PATH
export PATH
qmake -config release
make

"make" did this

g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.8.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.8.2/include/QtCore -I/usr/local/Trolltech/Qt-4.8.2/include/QtGui -I/usr/local/Trolltech/Qt-4.8.2/include -I. -o main.o main.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.8.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.8.2/include/QtCore -I/usr/local/Trolltech/Qt-4.8.2/include/QtGui -I/usr/local/Trolltech/Qt-4.8.2/include -I. -o findscenario.o findscenario.cpp
/usr/local/Trolltech/Qt-4.8.2/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.8.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.8.2/include/QtCore -I/usr/local/Trolltech/Qt-4.8.2/include/QtGui -I/usr/local/Trolltech/Qt-4.8.2/include -I. findscenario.h -o moc_findscenario.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.8.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.8.2/include/QtCore -I/usr/local/Trolltech/Qt-4.8.2/include/QtGui -I/usr/local/Trolltech/Qt-4.8.2/include -I. -o moc_findscenario.o moc_findscenario.cpp
g++ -Wl,-O1 -Wl,-rpath,/usr/local/Trolltech/Qt-4.8.2/lib -o findscenario main.o findscenario.o moc_findscenario.o -L/usr/local/Trolltech/Qt-4.8.2/lib -L/usr/local/Trolltech/Qt-4.8.2/lib -lQtGui -L/usr/X11R6/lib -lQtCore -lpthread

then I wrote
ldd ./the_name_of_the_executable and it says

elina@debian:~/Desktop/findscenario$ ldd ./findscenario
linux-gate.so.1 => (0xb775d000)
libQtGui.so.4 => /usr/local/Trolltech/Qt-4.8.2/lib/libQtGui.so.4 (0xb6be5000)
libQtCore.so.4 => /usr/local/Trolltech/Qt-4.8.2/lib/libQtCore.so.4 (0xb68fe000)
libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb68d8000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb67e3000)
libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb67bd000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb679f000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb6658000)
libz.so.1 => /usr/lib/libz.so.1 (0xb6643000)
libSM.so.6 => /usr/lib/libSM.so.6 (0xb663b000)
libICE.so.6 => /usr/lib/libICE.so.6 (0xb6624000)
libXext.so.6 => /usr/lib/libXext.so.6 (0xb6615000)
libX11.so.6 => /usr/lib/libX11.so.6 (0xb64f8000)
libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb64f3000)
librt.so.1 => /lib/i686/cmov/librt.so.1 (0xb64ea000)
/lib/ld-linux.so.2 (0xb775e000)
libuuid.so.1 => /lib/libuuid.so.1 (0xb64e6000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0xb64cd000)
libXau.so.6 => /usr/lib/libXau.so.6 (0xb64ca000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0xb64c4000)

2) Is it ok? I think no :p
And when i add the folder with my project in a new debian that hasn't Qt libraries and it says

error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory

3) Why shared libraries?
What do I do wrong?

Thanks in advance :)

wysota
25th July 2012, 19:02
What does qmake -v return? What is the content of the lib folder under your Qt installation path?