Louie Mazin
Louie Mazin

Reputation: 83

Executing a binary with a shared library in linux

I am making a simple hello world program to learn about linking shared libraries in linux. I have managed to compile the main program into an executable with the shared library using the following:

g++ -fPIC -c lab2_hello_main.cpp    <--create position independent objects

g++ -fPIC -c lab2_hello_sub.cpp

g++ -fPIC -shared -Wl,-soname=libfuncs.so.1.0 *.o -o libfuncs.so.1.0 -lc <--make the shared library

ln -s libfuncs.so.1.0 libfuncs.so <-- soft links for compiling and running

ln -s libfuncs.so.1.0 libfuncs.so.1

g++ -o hello_dyn lab2_hello_main.cpp -L/mypath -lfuncs <-- Linking the library to main

When I do an ldd on hello_dyn I get an output stating that the library can't be found:

"libfuncs.so.1.0 => not found" The other libraries it looks for automatically are fine.

Anyone know why this might be?

Upvotes: 2

Views: 3394

Answers (1)

Void - Othman
Void - Othman

Reputation: 3481

Your shared library's location is not in the linker's search path. You can confirm this by adding the directory in which your library is located to the LD_LIBRARY_PATH environment variable and then run ldd again. See the ld.so(8) man page for details.

Upvotes: 1

Related Questions