Home > other >  cannot open shared object file: No such file or directory | including libbpf with userspace program
cannot open shared object file: No such file or directory | including libbpf with userspace program

Time:01-14

So in my userspace program I am calling some functions like bpf_object__open_file which are part of libbpf library installed with PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make install

So when I compile the it compiles just fine, no error with this command

  clang -L /build/root/usr/lib64/ -I /usr/include/ -Wall -o user u.c -lbpf

so these files exists in my /build/root/usr/lib64 directory

    libbpf.a  libbpf.so  libbpf.so.0  libbpf.so.0.7.0  pkgconfig

But when I run the program like

 sudo ./user

It throws message that

 ./user: error while loading shared libraries: libbpf.so.0: cannot open shared object file: No such file or directory

So basically I am creating shared library, giving the path but why running the program not able to find my libbpf.so.0 shared library

can anyone tell why is that the case I am getting message can't find library

As Qeole mentioned in comment

So I did this

root@/dir/# ldd ./user

and it gives me this output without any location where did it tried to find path directory

linux-vdso.so.1 (0x00007ffcd77e7000)
libbpf.so.0 => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9b3943c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9b39642000)

CodePudding user response:

You should add the libbpf library directory to your LD_LIBRARY_PATH variable.

$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/build/root/usr/lib64
$ export LD_LIBRARY_PATH

Then go ahead an run the program. Note that if you run it with sudo, you may also need to set root's LD_LIBRARY_PATH

$ sudo su
# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/build/root/usr/lib64
# export LD_LIBRARY_PATH
# ./user

You can verify that libbfp was found with the same ldd command.

  •  Tags:  
  • Related