I'm writing two C programs. One of them uses library libnsd.so
. I compile two C programs using makefile which looks like this:
我在写两个C程序。其中一个使用图书馆libnsd。我用makefile编译了两个C程序,它看起来是这样的:
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
加载共享库时出错:libnsd。所以:不能打开共享对象文件:没有这样的文件或目录。
Anyone knows how to solve it?
有人知道怎么解决吗?
1 个解决方案
#1
2
The error msg means your program can't find the dynamic library libnsd.so
.
msg的错误意思是你的程序找不到动态库libnsd.so。
- 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.
如果lib不在常规路径上,我建议把它放在常规路径上。
whereis libnsd.so
那儿离libnsd.so
mv your_dir/libnsd.so /usr/local/lib
mv your_dir / libnsd。所以/usr/local/lib
Note: If the library is does not exist on your system, you should install it first.
注意:如果您的系统上没有库,那么应该先安装它。
- Then, use ldconfig to write the path in the config file:
- 然后,使用ldconfig在配置文件中写入路径:
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
出口LD_LIBRARY_PATH = / usr /地方/ lib:LD_LIBRARY_PATH美元
#1
2
The error msg means your program can't find the dynamic library libnsd.so
.
msg的错误意思是你的程序找不到动态库libnsd.so。
- 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.
如果lib不在常规路径上,我建议把它放在常规路径上。
whereis libnsd.so
那儿离libnsd.so
mv your_dir/libnsd.so /usr/local/lib
mv your_dir / libnsd。所以/usr/local/lib
Note: If the library is does not exist on your system, you should install it first.
注意:如果您的系统上没有库,那么应该先安装它。
- Then, use ldconfig to write the path in the config file:
- 然后,使用ldconfig在配置文件中写入路径:
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
出口LD_LIBRARY_PATH = / usr /地方/ lib:LD_LIBRARY_PATH美元