Error loading shared libraries: libnsd.so: cannot open shared objects file: no such file or directory

I am writing two programs in C. One of them uses a library libnsd.so. I will compile two C programs using a makefile that 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 start the application, I get an error message:

when loading shared libraries: libnsd.so: unable to share object file: No such file or directory

Does anyone know how to solve it?

+4
source share
1 answer

The msg error means that your program cannot find the dynamic library libnsd.so.

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

lib , .

whereis libnsd.so

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

. , .

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

, :

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

+2

Source: https://habr.com/ru/post/1569207/


All Articles