问题
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 ?
回答1:
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:
Download the latest version of Ghostscript from source:
wget http://downloads.ghostscript.com/public/ghostscript-9.14.tar.gzUnpack the tar:
tar -xzf ghostscript-9.14.tar.gzcd ghostscript-9.14./configuremake<-- You might be able to skip and go tomake so, I did it in this order so I will leave it like this.make installmake soIf you removed a previous version with yum
ln -s /usr/local/bin/gs /usr/bin/gscp ghostscript-9.14/sobin/libgs.so.9.14 /usr/libln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.sovi /etc/ld.so.conf.d/libgs.confIn the new libgs.conf file:
/usr/lib/libgs.soand save with esc, :,wq.ldconfigand done.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.
回答2:
I just had this issue on a linux VM. I was able to solve it by installing ghostscript on the system. I just used the command:
sudo yum install ghostscript
Hope that helps!
回答3:
make soinstall will create required libs along with executables as mentioned in https://www.ghostscript.com/doc/current/Install.htm#Shared_object
来源:https://stackoverflow.com/questions/17653569/unable-to-load-library-gs-libgs-so-cannot-open-shared-object-file-no-such-f