[英]Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory
I have installed ghostscript of 64 bit on my 64 bit linux machine. 我已经在64位linux机器上安装了64位的ghostscript。 I am using ghost4j-0.5.0.jar to convert pdf files to tiff files.
我正在使用ghost4j-0.5.0.jar将pdf文件转换为tiff文件。 I have written a java program which will convert pdf files to tiff files.
我写了一个Java程序,它将pdf文件转换为tiff文件。 This is working perfectly fine on Windows but when i thought of moving this to linux machine i am getting the below error.
这在Windows上运行正常,但是当我想到将其移至linux计算机时,出现以下错误。
"Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'gs': libgs.so: cannot open shared object file: No such file or directory" “线程“主”中的异常java.lang.UnsatisfiedLinkError:无法加载库'gs':libgs.so:无法打开共享对象文件:没有这样的文件或目录”
I checked lib folder and could not find libgs.so file in the lib folder. 我检查了lib文件夹,但在lib文件夹中找不到libgs.so文件。 I am not sure where to get that file.
我不确定从哪里获取该文件。
Can anyone please help me on this ? 有人可以帮我吗?
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. 我觉得有点内this,因为它可能最好在ServerFault或Linux板上之一上使用,并且这个问题已经存在了6个月以上,但是我整天都在碰壁,终于找到了解决方案问题,我想其他人可能会从中受益。
Systems: Windows 7
and CentOS 6.5
系统:
Windows 7
和CentOS 6.5
Using: Ghostscript 9.14
使用:
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. 像OP一样,我一直在Windows上运行ghostscript程序,以将PDF转换为一系列图像。 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
. 直到我需要切换到Linux并运行程序,并且我需要转换的大约5%的PDF出现
error cannot decode code stream
时,此方法error cannot decode code stream
。 I realized that I was using a newer version of ghostscript on Windows. 我意识到我在Windows上使用的是更新版本的ghostscript。 (9.14 on Windows compared to 8.70 on CentOS due to installing through yum).
(由于通过yum安装,Windows上为9.14,而CentOS上为8.70)。
I removed the old version with yum remove ghostscript
. 我用
yum remove ghostscript
删除了旧版本。 Next, I found the easiest way to install the newest version of Ghostscript is download from here and compile. 接下来,我发现从此处下载并编译即可安装最新版本的Ghostscript的最简单方法。 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
. 自从我用yum删除了上一个版本的ghostscript以来,我不得不用
ln -s /usr/local/bin/gs /usr/bin/gs
更新usr/bin
的链接以指向usr/local/bin/gs
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
. 我在这里遇到了一篇文章,说要获得必要的
libgs.so
所以我需要回过头来,使用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
. 我这样做,然后我把
libgs.so.9.14
文件下sobin
目录中的文件夹的Ghostscript和其复制到/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
. 在该目录下,我使用
ln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.so
命令建立了指向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. 完成此操作后,我需要更新
ld_library_path
但发现这样做时更改不是全局的,因此我找到了有关如何设置全局lib路径的Unix&Linux帖子 。 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. 基本上,您需要在
/etc/ld.so.conf.d/
添加一个.conf
文件以及该文件的路径。 I did so using vi /etc/ld.so.conf.d/libgs.conf
and added /usr/lib/libgs.so
to the file. 我使用
vi /etc/ld.so.conf.d/libgs.conf
做到了,并将/usr/lib/libgs.so
添加到文件中。 Lastly I ran ldconfig
so save the changes. 最后,我运行了
ldconfig
所以保存更改。
TLDR: TLDR:
Download the latest version of Ghostscript from source: wget http://downloads.ghostscript.com/public/ghostscript-9.14.tar.gz
从源代码下载最新版本的Ghostscript:
wget http://downloads.ghostscript.com/public/ghostscript-9.14.tar.gz
Unpack the tar: tar -xzf ghostscript-9.14.tar.gz
解压缩tar:
tar -xzf ghostscript-9.14.tar.gz
cd ghostscript-9.14
./configure
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. make
<-您可能可以跳过并执行make so
我按此顺序进行了操作,因此我将其保留为这样。
make install
make so
If you removed a previous version with yum ln -s /usr/local/bin/gs /usr/bin/gs
如果使用yum
ln -s /usr/local/bin/gs /usr/bin/gs
删除了先前版本
cp ghostscript-9.14/sobin/libgs.so.9.14 /usr/lib
ln -s /usr/lib/libgs.so.9.14 /usr/lib/libgs.so
vi /etc/ld.so.conf.d/libgs.conf
In the new libgs.conf file: /usr/lib/libgs.so
and save with esc , : , wq
. 在新的libgs.conf文件:
/usr/lib/libgs.so
与ESC保存,:, wq
。
ldconfig
and done. ldconfig
完成。
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.
我还不是Linux专家,因此使用上述命令可能会做一些不必要的工作,但我想更加详尽。
I just had this issue on a linux VM. 我刚在Linux VM上遇到这个问题。 I was able to solve it by installing ghostscript on the system.
我可以通过在系统上安装ghostscript来解决它。 I just used the command:
我只是使用了命令:
sudo yum install ghostscript
Hope that helps! 希望有帮助!
make soinstall
将创建必需的库以及可执行文件,如https://www.ghostscript.com/doc/current/Install.htm#Shared_object中所述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.