加载共享库时出错:libnsd.so:无法打开共享库文件:没有这样的文件或目录 [英] error while loading shared libraries: libnsd.so: cannot open shared object file: No such file or directory

查看:133
本文介绍了加载共享库时出错:libnsd.so:无法打开共享库文件:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写两个C程序.其中之一使用库libnsd.so.我使用makefile编译两个C程序,如下所示:

I'm writing two C programs. One of them uses library libnsd.so. I compile two C programs using makefile which looks like this:

CC=gcc
CFLAGS= -Wall -g -O -fPIC
RM= rm
HLAV=main
HLAVO=main.o


all:lib $(HLAV)
    cc c2.c -o c2


main: $(HLAVO)

    $(CC) -L. -o $(HLAV) $(HLAVO) -lnsd

lib: libnsd.so

libnsd.so: nsd.o nd.o
    $(CC) -shared $< -o $@



 nsd.o: nsd.c nsd.h nd.h

 nd.o: nd.c nsd.h nd.h



clean:
    $(RM) -rf *.o *.so main

当我尝试运行应用程序时,出现错误:

When I try to run an aplication I get an error:

加载共享库时出现

错误:libnsd.so:无法打开共享 目标文件:没有这样的文件或目录

error while loading shared libraries: libnsd.so: cannot open shared object file: No such file or directory

有人知道如何解决吗?

推荐答案

错误msg表示您的程序找不到动态库libnsd.so.

The error msg means your program can't find the dynamic library libnsd.so.

  1. 您需要从系统中找到库路径.

如果lib不在常规路径上,建议将其放在常规路径上.

If the lib is not on the regular path, I suggest put it on the regular path.

哪里是libnsd.so

whereis libnsd.so

mv your_dir/libnsd.so/usr/local/lib

mv your_dir/libnsd.so /usr/local/lib

注意:如果系统上不存在该库,则应首先安​​装它.

Note: If the library is does not exist on your system, you should install it first.

  1. 然后,使用ldconfig在配置文件中写入路径:

sudo echo "/usr/local/lib" >> /etc/ld.so.conf
sudo ldconfig

或者,如果您的工作站没有root特权,则只需更改用户环境路径即可:

Or if you don't have root priviledge in your workstation, you can simply change user environment path:

导出LD_LIBRARY_PATH =/usr/local/lib:$ LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

这篇关于加载共享库时出错:libnsd.so:无法打开共享库文件:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆