cirrusio
cirrusio

Reputation: 590

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?

Upvotes: 3

Views: 7424

Answers (2)

IMHarish
IMHarish

Reputation: 1

Actually it follows specific naming convention like library name should be preceded by lib. so if you change library name to libsession.so it will work.

Upvotes: 0

Bob
Bob

Reputation: 4970

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

Upvotes: 3

Related Questions