Error while loading shared libraries: on Linux

last updated in Categories , , , ,

I am trying to use wkhtmltopdf command to create and convert html pages to a pdf. However, I am running into errors though as follows when try to use wkhtmltopdf via a shell or Python script:
     Creating foo.pdf …
     ~/bin/wkhtmltox/bin/wkhtmltopdf: error while loading shared libraries: cannot open shared object file: No such file or directory
     Error: foo.pdf not found.

How do I fix this problem with out installing the xserver on my Ubuntu or Debian server?

You can find the missing libs using the ldd command:
$ ldd /path/to/wkhtmltopdf
Sample outputs: =>  (0x00007fffdd3c6000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64cd4bd000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64cd27a000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64ccfcf000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64ccdbd000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64cca83000) => /lib/x86_64-linux-gnu/ (0x00007f64cc868000) => /lib/x86_64-linux-gnu/ (0x00007f64cc664000) => /lib/x86_64-linux-gnu/ (0x00007f64cc45c000) => /lib/x86_64-linux-gnu/ (0x00007f64cc23e000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64cbebc000) => /lib/x86_64-linux-gnu/ (0x00007f64cbbb3000) => /lib/x86_64-linux-gnu/ (0x00007f64cb99c000) => /lib/x86_64-linux-gnu/ (0x00007f64cb5d3000)
	/lib64/ (0x00005564cb080000) => /lib/x86_64-linux-gnu/ (0x00007f64cb3aa000) => /lib/x86_64-linux-gnu/ (0x00007f64cb184000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64caf62000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64cad5d000) => /usr/lib/x86_64-linux-gnu/ (0x00007f64cab57000)

Now you can search for missing libs using:
$ apt-cache search libXrender
In my case the following were missing

  1. libXrender: X Rendering Extension client library
  2. libfontconfig1: generic font configuration library – runtime

Fixing error while loading shared libraries on a Ubuntu/Debian Linux

Armed with this new info, I need to use the following apt-get command or apt command to install libxrender1 and libfontconfig1 to solve this issue:
$ sudo apt-get install libfontconfig1 libxrender1
$ sudo apt install libfontconfig1 libxrender1
If you are using any other Linux distro you need to search as described above and install missing libs.

See also

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

1 comment

  1. Another solution is to do this:

    $ sudo apt-file search 
    libxrender1: /usr/lib/x86_64-linux-gnu/
    libxrender1: /usr/lib/x86_64-linux-gnu/
    libxrender1-dbg: /usr/lib/debug/usr/lib/x86_64-linux-gnu/

    Still, have a question? Get help on our forum!