且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法加载库'gs':libgs.so:无法打开共享对象文件:没有这样的文件或目录

更新时间:2022-01-21 08:10:32

我觉得这里有点内疚,因为它可能更适合在ServerFault或其中一个Linux主板上使用,这个问题已经超过6个月了,但我整天都在撞墙。最后找到了这个问题的解决方案,我想其他人可能会从中获益。

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.

系统: Windows 7 CentOS 6.5

使用: Ghostscript 9.14

一个小故事:

就像我一直在运行的OP Windows上的ghostscript程序将PDF转换为一系列图像。这工作正常,直到我需要切换到Linux并运行程序,我需要转换的大约5%的PDF出现错误无法解码代码流。我意识到我在Windows上使用的是较新版本的ghostscript。 (在Windows上为9.14,而由于通过yum安装,在CentOS上为8.70)。

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).

我删除了旧版本的 yum remove ghostscript 。接下来,我发现安装最新版Ghostscript的最简单方法是从这里下载并编译。由于我用yum删除了之前版本的ghostscript,我不得不更新 usr / bin 中的链接指向 usr / local / bin / gs with ln -s / usr / local / bin / gs / usr / bin / gs 。随着一切到位,所以我想,我试图运行我的程序然后bam,错误!

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!

解决问题:

所以现在我收到了错误:

So now I was getting the error:

线程mainjava.lang中的异常.UnsatisfiedLinkError:无法加载库'gs':libgs.so:无法打开共享对象文件:没有这样的文件或目录

我来了在这里的帖子中说要获得必要的 libgs.so 我需要返回并使用命令重建源作为共享库使这样。我这样做了然后我在ghostscript文件夹中的 sobin 目录下取了 libgs.so.9.14 文件并复制了它到 / usr / lib 。在该目录下,我使用命令 ln -s /usr/lib/libgs.so.9.14 / usr /建立了一个符号链接到 libgs.so LIB / libgs.so

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.

一旦完成,我需要更新我的 ld_library_path ,但在我这样做时发现变化不是全局的所以我找到了一个 Unix& ;关于如何设置全局lib路径的Linux帖子。基本上这样做你需要在 /etc/ld.so.conf.d / $ c $中添加一个 .conf 文件。 c>带有文件的路径。我使用 vi /etc/ld.so.conf.d/libgs.conf 并添加了 /usr/lib/libgs.so 到该文件。最后我运行 ldconfig ,所以保存更改。

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. 从源代码下载最新版本的Ghostscript: wget http://downloads.ghostscript.com/ public / ghostscript-9.14.tar.gz

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

解压缩tar: tar -xzf ghostscript-9.14 .tar.gz

cd ghostscript-9.14

./ configure

make < - 您可以跳过并转到 make so ,我是按此顺序完成的,所以我会保持这样。

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 install

make so

如果您使用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$c $ c>

在新的libgs.conf文件中: /usr/lib/libgs.so 并使用 esc wq 保存。

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

ldconfig 已完成。

运行转换程序。

希望这有助于并且不会太混乱。我不是Linux专家(还),所以我可能会用上述命令做一些不必要的工作,但我想要彻底。

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.