Question

I am making use of a logging library, named liblogger, (that I've implemented) within another library, libmsg. For both of them, I'm using the autotools. I successfully install the liblogger library in my system, under the /usr/local/lib directory.

Within the configure.ac script of the other libmsg, I verify that liblogger is installed in the system, as follows:

AC_CHECK_LIB([logger],
             [log_init],
             [],
             [
              echo "Error: Could not find liblogger."
              exit 1
             ])

And add the "-L/usr/local/lib" path to the LDFLAGS variable.

The AC_CHECK_LIB test finds the library, and both the libmsg library and its check_PROGRAMS using are successfully compiled.

However, when I try to execute the test programs, I get the error:

error while loading shared libraries: liblogger.so.0: cannot open shared object file: No such file or directory

Indeed, ldd does not find the library either:

$ ldd msgs
  linux-vdso.so.1 => (0x00007fff543ff000) 
  liblogger.so.0 => not found
  libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fdf329ad000)

But the library is actually there, in /usr/local/lib.

For linking the test program, libtool is being called with the instruction:

$ /bin/bash ../libtool --tag=CC   --mode=link gcc -I../include -I../msg -L/usr/local/lib -O2 -Wall -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include   -I/usr/local/include -I/usr/local/lib  -L/usr/local/lib -o msgs msgs.o message.o base64.o misc.o  -llogger  -lglib-2.0

Which actually echoes the following:

libtool: link: gcc -I../include -I../msg -O2 -Wall -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include -I/usr/local/lib -o msgs msgs.o message.o base64.o misc.o  -L/usr/local/lib /usr/local/lib/liblogger.so -lglib-2.0

So, the -llogger flag is being substituted by -L[..] /usr/local/liblogger.so (I suppose this is a correct behavior? I haven't been able yet to determine it...)

Actually, if I call the test program with:

LDPRELOAD=/usr/local/lib/liblogger.so msgs

It actually works.

Can anyone tell me what is it what I'm missing?

Was it helpful?

Solution

You need to check if:

  • /usr/local/lib is in /etc/ld.so.conf (it usually is these days).
  • ldconfig was run when you installed liblogger. If not, run it.
  • liblogger.so.0 is actually in /usr/local/lib.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top