2

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)
user786
  • 3,902
  • 4
  • 40
  • 72
  • 1
    Did you see this question? https://stackoverflow.com/questions/480764/linux-error-while-loading-shared-libraries-cannot-open-shared-object-file-no-s – Gerhardh Jan 13 '22 at 12:49
  • 2
    `ldd ./user` should also tell you where the system expects to find the libraries, I believe. – Qeole Jan 13 '22 at 12:55
  • @Qeole I tried ldd command it gives me this `libbpf.so.0 => not found` – user786 Jan 13 '22 at 13:43

1 Answers1

2

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.

Daniel Byrne
  • 111
  • 4
  • ok thanks it worked but now I am getting error `root@fawad-HP-Pavilion-dm4-Notebook-PC:/home/fawad/Desktop# ./user libbpf: elf: c.o is not a valid eBPF object file ERROR: opening BPF object file failed root@f` – user786 Jan 13 '22 at 14:39
  • do u know how to make clang find arch asm/types.h. I think I had to use -I or something like `clang -arch` but the later one throwing tons of error and the earlier one not finding it – user786 Jan 13 '22 at 14:55
  • `clang -I /path/to/asm/types.h` should include the file for you. as far as your other error, it seems the program does not recognize file c.o as valid eEBF file. you might need to find the correct input file. – Daniel Byrne Jan 13 '22 at 18:53