Getting error while loading shared libraries when using -L to find a library

I have been trying to solve this for several hours. I am compiling some c files with gcc. Files require libpbc, so I use the -L flag to specify gcc in the directory that contains libpbc.so.1. The code compiles without errors, but when I try to run it, I get the following error message:

./example.out: error loading shared libraries: libpbc.so.1: cannot open shared objects file: no such file or directory

If you look at such questions, this error message seems to indicate that gcc cannot find libpbc.so.1. I know that gcc sees libpbc.so.1 because when I rename libpbc.so.1 to something else, it does not compile.

I use -L to point to the directory containing libpbc.so.1.

I don’t know what steps I can take to understand this. Any ideas will be appreciated. What does this error message mean?

EDIT

Running ldd example.out results in:

linux-gate.so.1 => (0xb7fe3000) libpbc.so.1 => not found libgmp.so.3 => /usr/lib/libgmp.so.3 (0xb7f87000) 
+4
source share
2 answers
 ldd example.out 

This will provide a lot of useful information about dynamic linking. More specifically, your problem is most likely due to the library not being located.

 /etc/ld.so.conf 

Please note that if you update this file, you must run

 ldconfig -v 
+6
source

Specify the rpath flag when compiling.

 g++ -Wall -o example.out -I ./include/ -L ./examplelibPath -Wl,-rpath ./libPath -l examplelibrary example.cpp 
+1
source

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


All Articles