Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a binary here that is apparently statically linked:

$ file wkhtmltopdf-amd64
wkhtmltopdf-amd64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), 
                   statically linked, stripped

$ ldd wkhtmltopdf-amd64
not a dynamic executable

$ readelf -d wkhtmltopdf-amd64 
There is no dynamic section in this file.

But when i try to execute it, it complains that shared libs would be missing:

$ ./wkhtmltopdf-amd64 
./wkhtmltopdf-amd64: error while loading shared libraries: 
   libXrender.so.1: cannot open shared object file: No such file or directory

My questions:

  • I thought statically linked binaries do not depend on shared libraries. Can someone correct my obviously wrong assumption?
  • How can I find all the libraries this binary is depending on?

PS: The binary in question is from here: http://code.google.com/p/wkhtmltopdf/downloads/list

share|improve this question
    
Easiest thing would probably be to download the source and compile it yourself. If probably tells you what libraries it needs in the configure script or a text file. If not the errors you get configuring and compiling it will tell you. –  Grant Mar 19 '13 at 23:50

1 Answer 1

Yes, indirectly through embedded libraries.

The information below suggests that that the QT library is statically embedded in the binary. Running the binary with strace, reveals that it indeed tries to load Xorg libraries because those are not statically linked in the QT libraries. In other words, some of the statically linked libraries (most likely QT) have dependencies of their own. At least that's what I think.

wkhhtmltopdf wiki - compilation:

Before you can compile wkhtmltopdf you need to have QT installed, again you have two options: You can install the QT from your distribution, this will be fast but your wkhtmltopdf build will not have all the features of the static build, or you can compile QT your self, this takes a long time but you will get all the features.

wkhtmltopdf wiki - static (faq):

  • I'm using the static binary but the fonts are wrong, squares or all black?
    This is most likely because you do not have X11 installed or not the right X11 fonts

QtGui depends on Xorg & Co:

# qlist  qtgui |grep lib.*\.so | awk -F/ '{print $NF}' |column
libqtiff.so                             libQtScriptTools.so.4
libqjpeg.so                             libQtDesignerComponents.so.4.8
libqico.so                              libQtGui.so
libqgif.so                              libQtScriptTools.so
libqimsw-multi.so                       libQtGui.so.4
libqtaccessiblewidgets.so               libQtDesigner.so
libQtDesigner.so.4.8.4                  libQtDesignerComponents.so.4
libQtGui.so.4.8.4                       libQtGui.so.4.8
libQtDesigner.so.4                      libQtDesigner.so.4.8
libQtScriptTools.so.4.8.4               libQtScriptTools.so.4.8
libQtDesignerComponents.so.4.8.4        libQtDesignerComponents.so

       (>>> depend on)

# qlist  qtgui |grep lib.*\.so |xargs -L1 ldd | awk '{print $1}'| sort -u|column
libbz2.so.1             libpthread.so.0         libxcb.so.1
libc.so.6               libQtCore.so.4          libXcursor.so.1
libdl.so.2              libQtDesigner.so.4      libXdmcp.so.6
libexpat.so.1           libQtGui.so.4           libXext.so.6
libfontconfig.so.1      libQtScript.so.4        libXfixes.so.3
libfreetype.so.6        libQtXml.so.4           libXinerama.so.1
libgcc_s.so.1           librt.so.1              libXi.so.6
libglib-2.0.so.0        libSM.so.6              libXrandr.so.2
libICE.so.6             libstdc++.so.6          libXrender.so.1
libjpeg.so.8            libtiff.so.3            libz.so.1
/lib/ld-linux.so.2      libuuid.so.1            linux-gate.so.1
libm.so.6               libX11.so.6
libpng15.so.15          libXau.so.6

Also, I compiled the program from the repository of my distro (dynamic) and the differences between openStatic and openDynamic are:

# function openStatic { strace ./wkhtmltoimage/static/wkhtmltoimage-i386 \
      |& grep 'open.*3' |sort | grep -o '/[^"]*' ;}

# openStatic
/etc/ld.so.cache         /usr/lib/libexpat.so.1
/lib/ld-linux.so.2       /usr/lib/libfontconfig.so.1
/lib/libbz2.so.1         /usr/lib/libfreetype.so.6
/lib/libc.so.6           /usr/lib/libX11.so.6
/lib/libdl.so.2          /usr/lib/libXau.so.6
/lib/libgcc_s.so.1       /usr/lib/libxcb.so.1
/lib/libm.so.6           /usr/lib/libXdmcp.so.6
/lib/libpthread.so.0     /usr/lib/libXext.so.6
/lib/librt.so.1          /usr/lib/libXrender.so.1
/lib/libz.so.1
/usr/lib/gcc/i686-pc-linux-gnu/4.5.3/libstdc++.so.6
------ Statically embedded libraries ------     --- Dynamically linked dependencies ---
1 l/ld-linux.so.2               1 ul/libk5crypto.so.3      2 /etc/ld.so.cache
1 l/libcom_err.so.2             1 ul/libkrb5.so.3          2 /lib/libbz2.so.1
1 l/libkeyutils.so.1            1 ul/libkrb5support.so.0   2 /lib/libc.so.6
1 l/libresolv.so.2              1 ul/liborc-0.4.so.0       2 /lib/libdl.so.2
1 l/libuuid.so.1                1 ul/libpng15.so.15        2 /lib/libgcc_s.so.1
1 ul/gconv/gconv-modules.cache  1 ul/libSM.so.6            2 /lib/libm.so.6
1 ul/gconv/UTF-16.so            1 ul/libsqlite3.so.0       2 /lib/libpthread.so.0
1 ul/libcrypto.so.1.0.0         1 ul/libssl.so.1.0.0       2 /lib/librt.so.1
1 ul/libffi.so.5                1 ul/libwkhtmltox.so.0     2 /lib/libz.so.1
1 ul/libglib-2.0.so.0           1 ul/libXcursor.so.1       2 ul/gcc/.../libstdc++.so.6
1 ul/libgmodule-2.0.so.0        1 ul/libXfixes.so.3        2 ul/libexpat.so.1
1 ul/libgobject-2.0.so.0        1 ul/libXinerama.so.1      2 ul/libfontconfig.so.1
1 ul/libgstapp-0.10.so.0        1 ul/libXi.so.6            2 ul/libfreetype.so.6
1 ul/libgstbase-0.10.so.0       1 ul/libxml2.so.2          2 ul/libX11.so.6
1 ul/libgstinterfaces-0.10.so.0 1 ul/libXrandr.so.2        2 ul/libXau.so.6
1 ul/libgstpbutils-0.10.so.0    1 ul/qt4/libQtCore.so.4    2 ul/libxcb.so.1
1 ul/libgstreamer-0.10.so.0     1 ul/qt4/libQtGui.so.4     2 ul/libXdmcp.so.6
1 ul/libgstvideo-0.10.so.0      1 ul/qt4/libQtNetwork.so.4 2 ul/libXext.so.6
1 ul/libgthread-2.0.so.0        1 ul/qt4/libQtSvg.so.4     2 ul/libXrender.so.1
1 ul/libICE.so.6                1 ul/qt4/libQtWebKit.so.4

more info:
static linking
your question on SO (duplicate, wink-wink)

share|improve this answer
    
Would be nice if someone with a real grasp of linking would add a paragraph on how this stuff really works without all the "experimentation" –  Ярослав Рахматуллин Mar 22 '13 at 1:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.