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

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

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:

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

Anyone knows how to solve it?

回答1:

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

  1. You need to find the library path from your system.

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

whereis libnsd.so

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. Then, use ldconfig to write the path in the config file:
sudo echo "/usr/local/lib" >> /etc/ld.so.conf sudo ldconfig 

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

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!