Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ cannot find shared library

I apologize that this is redundant, but none of the answers available seem to be able to solve my problem. I am attempting to compile an executable using a shared object library. The shared object library is called libsession.so and is found in the same directory that I am compiling the executable. To compile and link, I use the following command

g++ test_main.cpp -o program -std=c++11 -I ../src/base -L. -lsession

Unforutanely, I get the cannot find -lsession error when linking. If I change the command to directly reference the shared library as follows

g++ test_main.cpp -o program -std=c++11 -I ../src/base libsession.so

then the executable compiles/links and all is well. Does anyone have any thoughts as to what I may be doing wrong?

like image 652
cirrusio Avatar asked Jun 30 '26 12:06

cirrusio


1 Answers

The only difference between using an '-l' option and specifying a file name is that '-l' surrounds library with 'lib' and `.a' and searches several directories.

https://gcc.gnu.org/onlinedocs/gcc-3.0/gcc_3.html#SEC16

like image 80
Bob Avatar answered Jul 03 '26 06:07

Bob