Shared Libraries

If you have your own shared libraries with the whole set of your favorite functions, probably you will have seen this common error:

./myapp: error while loading shared libraries: libtest.so: cannot open shared object file: No such file or direct

Let’s take a look inside the binary:

tuxedo@host:$> ldd test
    linux-gate.so.1 =>  (0xb7ef6000)
    libatest.so => not found
    libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7d81000)

By default the system is looking for in the paths defined in the /etc/ld.so.conf, which recursively adds the definitions in the folder /etc/ld.so.conf.d Here’s the quick trick:

tuxedo@host:$> export LD_LIBRARY_PATH=`pwd` 

I use this whereas I’m implementing my library, after that you can put it wherever you feel like.

tuxedo@host:$> ldd test
linux-gate.so.1 =>  (0xb7f5e000)
    libtest.so => /home/tuxedo/syslib/libtest.so (0xb7f56000)
    libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7de3000)
    /lib/ld-linux.so.2 (0xb7f5f000)

Now the executable will work. I’ll retake this issue, I have some interesting things to tell about shared libraries. Happy coding!!

Comments