加载共享库时出错
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试以 root 身份运行 ldconfig 看看是否可以解决问题。
Try running
ldconfig
as root to see if it solves the problem.运行 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.有很多方法可以做到这一点,这里已经提到了大多数方法。但是您希望避免意外地将库文件复制到系统的库文件中/覆盖系统的库文件。这很容易做到,因为人们在为他们的图书馆起原创的独特名称方面缺乏想象力。
因此,需要考虑以下几点:
要查找系统上的各个库位置(除了使用 find 之外),请查看此处:
在 Linux 上有一些标准位置:还有
很多其他位置,但您最有可能应该留在
/usr/local/lib
/usr/local/lib代码>.接下来,您需要告诉系统在哪里可以找到这些库。很酷的系统家伙(谁知道他在做什么)执行此操作的方法是使用 ldconfig ,但是,如果您在这里犯了错误,您可能会做一些让您后悔的事情。使用该命令的最安全方法是使用标志
-v -n
使命令变得详细并指定您需要添加的库目录。完毕。但如果您只想测试某些内容,则可以直接从命令行使用
LD_LIBRARY_PATH
,如下所示:或者,将以下内容添加到您的
.bashrc
脚本中。现在您可以运行动态链接的命令。
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:
To find your various library locations on your system (apart from using find), look here:
On Linux there are some standard places:
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.Done. But if you only wanna test something, then rather use your
LD_LIBRARY_PATH
directly from command line, like this:Alternatively, add the following to your
.bashrc
script.Now you can run your dynamically linked command.
我将所有库文件从 /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.
尝试安装库libxerces-c3.1 as。使用下面提到的命令来安装库。
这对我来说就像一个魅力。
Try installing the library libxerces-c3.1 as. Use the command mentioned below to install the library.
This worked like a charm for me.