加载共享库时出错

发布于 2024-10-09 00:56:22 字数 930 浏览 5 评论 0原文

我正在使用 g++ 编译器在 Ubuntu 上运行 eclipse,并且尝试运行一个利用 xerces 的示例程序。

构建没有产生错误,但是,当我尝试运行该程序时,我会收到此错误:

加载共享库时出错:libxerces-c-3.1.so:无法打开共享对象文件:没有这样的文件或目录

libxerces-c-3.1.so 在目录中/opt/lib 我已将其作为库包含在 Eclipse 中。当我检查文件夹时,该文件就在那里。当我执行 echo $LD_LIBRARY_PATH 时,还会列出 /opt/lib

对问题出在哪里有什么想法吗?谢谢。

ldd libxerces-c-3.1.so 命令产生以下输出:

linux-vdso.so.1 =>  (0x00007fffeafff000)
libnsl.so.1 => /lib/libnsl.so.1 (0x00007fa3d2b83000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fa3d2966000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fa3d265f000)
libm.so.6 => /lib/libm.so.6 (0x00007fa3d23dc000)
libc.so.6 => /lib/libc.so.6 (0x00007fa3d2059000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fa3d1e42000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa3d337d000)

I'm running eclipse on Ubuntu using a g++ compiler and I'm trying to run a sample program that utilizes xerces.

The build produced no errors however, when i attempted to run the program, I would receive this error:

error while loading shared libraries: libxerces-c-3.1.so: cannot open shared object file: No such file or directory

libxerces-c-3.1.so is in the directory /opt/lib which I have included as a library in eclipse. The file is there when I checked the folder. When I perform an echo $LD_LIBRARY_PATH, /opt/lib is also listed.

Any ideas into where the problem lies? Thanks.

An ldd libxerces-c-3.1.so command yields the following output:

linux-vdso.so.1 =>  (0x00007fffeafff000)
libnsl.so.1 => /lib/libnsl.so.1 (0x00007fa3d2b83000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fa3d2966000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fa3d265f000)
libm.so.6 => /lib/libm.so.6 (0x00007fa3d23dc000)
libc.so.6 => /lib/libc.so.6 (0x00007fa3d2059000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fa3d1e42000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa3d337d000)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

那请放手 2024-10-16 00:56:22

尝试以 root 身份运行 ldconfig 看看是否可以解决问题。

Try running ldconfig as root to see if it solves the problem.

夕色琉璃 2024-10-16 00:56:22

运行 ldd libxerces-c-3.1.so 并检查输出以查看是否可以找到所有依赖项。

Run ldd libxerces-c-3.1.so and examine the output to see if all dependencies can be found.

错々过的事 2024-10-16 00:56:22

有很多方法可以做到这一点,这里已经提到了大多数方法。但是您希望避免意外地将库文件复制到系统的库文件中/覆盖系统的库文件。这很容易做到,因为人们在为他们的图书馆起原创的独特名称方面缺乏想象力。

因此,需要考虑以下几点:

  • 您是否需要这些文件成为系统的永久部分?
  • 您是否只需要安装用于测试和频繁更新?
  • 您是否只需要它们来运行该特定命令一次或两次?
  • 您的本地库位于哪里?

要查找系统上的各个库位置(除了使用 find 之外),请查看此处:

cat /etc/ld.so.conf    
cat /etc/ld.so.conf.d/*

在 Linux 上有一些标准位置:还有

/lib            # for base system (don't use this!)
/usr/lib        # for package manger installed apps 
/usr/local/lib  # for user installed apps

很多其他位置,但您最有可能应该留在 /usr/local/lib/usr/local/lib代码>.
接下来,您需要告诉系统在哪里可以找到这些库。很酷的系统家伙(谁知道他在做什么)执行此操作的方法是使用 ldconfig ,但是,如果您在这里犯了错误,您可能会做一些让您后悔的事情。使用该命令的最安全方法是使用标志 -v -n 使命令变得详细并指定您需要添加的库目录。

sudo ldconfig -v -n /usr/local/lib/your-uber-libs

完毕。但如果您只想测试某些内容,则可以直接从命令行使用 LD_LIBRARY_PATH,如下所示:

LD_LIBRARY_PATH=/usr/local/lib/your-uber-libs ./your_uber_command

或者,将以下内容添加到您的 .bashrc 脚本中。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/your-uber-libs

现在您可以运行动态链接的命令。

There are many ways to do this, most already mentioned here. BUT you want to avoid accidentally copying your library files into/over those of the system. This is easily done since people have little imagination in making original unique names for their libraries.

So there are a couple of things to think about:

  • Do you need these files to be a permanent part of your system?
  • Do you only need to install for testing and frequent updates?
  • Do you only need them for running that particular command once or twice?
  • Where are your native libraries located?

To find your various library locations on your system (apart from using find), look here:

cat /etc/ld.so.conf    
cat /etc/ld.so.conf.d/*

On Linux there are some standard places:

/lib            # for base system (don't use this!)
/usr/lib        # for package manger installed apps 
/usr/local/lib  # for user installed apps

There are many others, but you should most likely stay with /usr/local/lib.
Next you need to tell your system where to find these libraries. The cool system dude (who knows what he is doing) way to do this is using ldconfig, however, you may do stuff you regret, if you make a mistake here. The safest way to use that command is by using the flags -v -n to make the command verbose and to specify what library directory you need to add.

sudo ldconfig -v -n /usr/local/lib/your-uber-libs

Done. But if you only wanna test something, then rather use your LD_LIBRARY_PATH directly from command line, like this:

LD_LIBRARY_PATH=/usr/local/lib/your-uber-libs ./your_uber_command

Alternatively, add the following to your .bashrc script.

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/your-uber-libs

Now you can run your dynamically linked command.

So要识趣 2024-10-16 00:56:22

我将所有库文件从 /opt/lib 复制到 /usr/lib 中,程序现在可以运行了。感谢您的回复。

I copied all the library files from /opt/lib into /usr/lib and the program works now. Thanks for the response.

川水往事 2024-10-16 00:56:22

尝试安装库libxerces-c3.1 as。使用下面提到的命令来安装库。

 sudo apt-get install libxerces-c3.1

这对我来说就像一个魅力。

Try installing the library libxerces-c3.1 as. Use the command mentioned below to install the library.

 sudo apt-get install libxerces-c3.1

This worked like a charm for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文