PDA

View Full Version : Static linking with Qt



prykHetQuo
2nd June 2009, 19:52
Qt version: 4.5.1

I followed the instructions at

http://doc.trolltech.com/4.5.1/deployment-x11.html#building-qt-statically

and I built Qt statically.


Then I compiled statically an application of mine.


However that page mentions:



To check that the application really links statically with Qt, run the ldd tool (available on most Unices):

ldd ./application

Verify that the Qt libraries are not mentioned in the output.



My application does not run as stand alone, producing the following:



john@ubuntu810-64:~/Desktop/download$ ./optics
./optics: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory



and the aforementioned "ldd ./application" produces:



john@ubuntu810-64:~/Desktop/download$ ldd ./optics
linux-vdso.so.1 => (0x00007fff6e5fe000)
libQtGui.so.4 => not found
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x00007f5e66015000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f5e65d91000)
libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007f5e65b4b000)
libSM.so.6 => /usr/lib/libSM.so.6 (0x00007f5e65942000)
libICE.so.6 => /usr/lib/libICE.so.6 (0x00007f5e65727000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00007f5e6551d000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00007f5e652eb000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00007f5e650d9000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f5e64dd1000)
libQtNetwork.so.4 => not found
libQtCore.so.4 => not found
libz.so.1 => /usr/lib/libz.so.1 (0x00007f5e64bb9000)
libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0x00007f5e649b4000)
librt.so.1 => /lib/librt.so.1 (0x00007f5e647ab000)
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f5e644e6000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f5e642e2000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f5e640c6000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f5e63db9000)
libm.so.6 => /lib/libm.so.6 (0x00007f5e63b34000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f5e6391c000)
libc.so.6 => /lib/libc.so.6 (0x00007f5e635aa000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007f5e63380000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f5e6317e000)
libxcb-xlib.so.0 => /usr/lib/libxcb-xlib.so.0 (0x00007f5e62f7c000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f5e62d60000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5e6623c000)
libpcre.so.3 => /lib/libpcre.so.3 (0x00007f5e62b37000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f5e62932000)
john@ubuntu810-64:~/Desktop/download$


If I understand correctly, the "not found" libraries are the only ones not statically linked in the executable.

Any ideas on how to achieve this?


Thanks.

wysota
2nd June 2009, 20:58
No. All the libraries mentioned here are linked dynamically. You didn't compile your application statically, at least not against any of the libraries mentioned in the output you posted.

prykHetQuo
3rd June 2009, 20:30
Can we explicitly specify at make or qmake the static library files we want to link?

lni
3rd June 2009, 20:56
Can we explicitly specify at make or qmake the static library files we want to link?

In Linux, if you just say -lfoo, the linker will look for libfoo.so first, if not found, then it looks for libfoo.a. From your ldd outputs, you have dynamic Qt libraries in the path...

You can force it to link to static one using -Wl,-Bstatic as

LIBS += -Wl,-Bstatic -lfoo

Then it will pick up static first. Try to play with your pro file, you should be able to figure it out...