Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory

Jai picture Jai · Jul 15, 2013 · Viewed 7.8k times · Source

I have installed ghostscript of 64 bit on my 64 bit linux machine. I am using ghost4j-0.5.0.jar to convert pdf files to tiff files. I have written a java program which will convert pdf files to tiff files. This is working perfectly fine on Windows but when i thought of moving this to linux machine i am getting the below error.

"Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory"

I checked lib folder and could not find libgs.so file in the lib folder. I am not sure where to get that file.

Can anyone please help me on this ?

Answer

Dan picture Dan · Mar 28, 2014

I feel a little guilty posting this here since it is probably better served on ServerFault or one of the Linux boards and the question is over 6 months old but I had been banging my head against the wall all day and finally have found a solution to this problem and I figured someone else might benefit from this down the road.

Systems: Windows 7 and CentOS 6.5

Using: Ghostscript 9.14

A little backstory:

Like the OP I had been running a ghostscript program on Windows to convert PDFs to a series of images. This worked fine until I needed to switch over to Linux and run the program and about 5% of the PDFs I needed to convert came up with error cannot decode code stream. I realized that I was using a newer version of ghostscript on Windows. (9.14 on Windows compared to 8.70 on CentOS due to installing through yum).

I removed the old version with yum remove ghostscript. Next, I found the easiest way to install the newest version of Ghostscript is download from here and compile. Since I removed the previous version of ghostscript with yum I had to update the link in usr/bin to point to usr/local/bin/gs with ln -s /usr/local/bin/gs /usr/bin/gs. With everything in place, so I thought, I attempted to run my program and then bam, error!

Solving the problem:

So now I was getting the error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory

I came across a post here that said to get the necessary libgs.so I needed to go back and rebuild the source as a shared library with the command make so. I did so and then I took the libgs.so.9.14 file under sobin directory in the ghostscript folder and copied it to /usr/lib. Under that directory I made a symbolic link to libgs.so using the command ln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.so.

Once that was done I needed to update my ld_library_path but found when I did so the change wasn't global so I found a Unix & Linux post on how to set the global lib path. Basically to do so you need to go to add a .conf file in /etc/ld.so.conf.d/ with the path to the file. I did so using vi /etc/ld.so.conf.d/libgs.conf and added /usr/lib/libgs.so to the file. Lastly I ran ldconfig so save the changes.

TLDR:

  1. Download the latest version of Ghostscript from source: wget http://downloads.ghostscript.com/public/ghostscript-9.14.tar.gz

  2. Unpack the tar: tar -xzf ghostscript-9.14.tar.gz

  3. cd ghostscript-9.14

  4. ./configure

  5. make <-- You might be able to skip and go to make so, I did it in this order so I will leave it like this.

  6. make install

  7. make so

  8. If you removed a previous version with yum ln -s /usr/local/bin/gs /usr/bin/gs

  9. cp ghostscript-9.14/sobin/libgs.so.9.14 /usr/lib

  10. ln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.so

  11. vi /etc/ld.so.conf.d/libgs.conf

  12. In the new libgs.conf file: /usr/lib/libgs.so and save with esc, :, wq.

  13. ldconfig and done.

  14. Run your conversion program.

Hopefully this helped and wasn't too confusing. I'm not a linux expert (yet) so I may be doing a little more work than necessary with the above commands but I wanted to be thorough.