Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems when linking shared library with GCC [duplicate]

I try to link a shared library just installed on my system, but for some reason the output doesn't want to execute. This is my compilation:

gcc -o test test.c -lgpio

When running the output, I get the following error:

./test: error while loading shared libraries: libgpio-3.0.0.so.3: cannot open shared object file: No such file or directory

Which is weird since I have this exact file in my /usr/local/lib-folder (along with libgpio-3.0.0.so and the other shared library files). I don't have much experience with GCC, so can someone please explain what went wrong?

like image 537
Totemi1324 Avatar asked Jul 17 '26 03:07

Totemi1324


1 Answers

Your library folder is probably not in the default search path. You'll need to specify it using the -L option when you compile:

gcc -L /usr/local/lib-folder -o test test.c -lgpio

You'll also need to add this folder to the LD_LIBRARY_PATH environment variable when you run the program.

like image 143
dbush Avatar answered Jul 19 '26 18:07

dbush



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!