Using gdb with Linux Elf shared object libraries

Using gdb with Linux Elf shared object libraries

Post by Robert D. Kenned » Sat, 20 Jun 1998 04:00:00


    I recently began debugging a product which distributes itself as a
set of shared object libraries. Try as I may, I have been unable to get
gdb (4.16 or 4.17) to load the shared object libraries, despite having
LD_LIBRARY_PATH set correctly. The programs will run stand-alone, but
fail to find my shared object libraries under gdb. I have tried using
the "share" command in gdb and still no luck.

    I tried the simplest example of making and using a program built of
of user shared object libraries, from Linux Application Development by
Michael K. Johnson and Eric W. Troan (ISBN 0-201-30821-5) p. 74-75.  My
file listings are given below, as well as the gdb output. Is this a
known defect in gdb on Linux? I saw some mention of this in
gnu.gdb.bugs, but the messages of interest seemed to have expired. Yet
some claim to be able to debug local (not in /etc/ shared
object libraries under Linux.

    My system is running Red Hat 5.0/Intel with all updates applied. I
am using gcc I compiled gdb 4.17 locally and got exactly the
same results. I tried preloading, and all ELF documented tricks, but
have made no reproducible progress.

Robert D. Kennedy
Fermi National Accelerator Laboratory


/* libhello.h */
void print_hello(void)

/* libhello.c */
#include <stdio.h>
void print_hello(void)
{ printf("Hello, from a shared library.\n") ;


/* usehello.c */
#include "libhello.h"
int main(void)
{print_hello() ;
  return 0 ;


% gcc -fPIC -Wall -g -c libhello.c
% gcc -g -shared -Wl,-soname, -o libhello.c
% #<make symlinks for,>
% gcc -g -Wall usehello.c -L. -lhello -o usehello
% setenv LD_LIBRARY_PATH $cwd
% ./usehello        # Works fine

gdb ./usehello # fails to load

b0pc07:Test> gdb ./usehello

GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for
GDB 4.16 (i386-redhat-linux), Copyright 1996 Free Software Foundation,
(gdb) run
Starting program: /usr/scratch/kennedy/Test/./usehello
/usr/scratch/kennedy/Test/./usehello: error in loading shared libraries cannot open shared object file: No such file or directory

Program exited with code 0177.


1. Trouble with gdb&Linux using transitive linked shared libraries

Hello Everybody,

currently I am porting a huge Softwareproject to Linux, where we
excessively used shared libraries ( *.so ), and of course all the
kinds of transitive/
recursive dependencies in the software project.
That means executable A links against, which itself is linked
against and, they are again.... and so on.

After some trouble with ld, (-rpath <directory> additional to
-L<directory> as on other Unix systems), we finally got it running on
But still, I am facing a lot of troubles in Debugging this kind of
since (ddd/)gdb does wierd things with dynamic loading of those

A) gdb opens only locally (cwd) available libraries - ignoring

B) (The most serios problem) On running "A", gdb complains about
unresolved symbols of, which are defined in, which are
available by
proper runtime linking - and are running without gdb.

Who has some answers - faced the same problems - solutions etc. ?
I cannot develop software without having a proper debugger.

Currently we are using gcc 2.95.3 / gdb 5.0

Thanks in advance,


2. Role Based Access Control

3. debugging a shared library using gdb on linux

4. FBSD 2.0.5/+ and ISDN Devices supported

5. Attempt to migrate a.out objects (Motif static library) to ELF objects

6. hdd input/output error

7. using gdb to step into a shared object

8. Debian, XFree, and APM

9. Using Shared Object Libraries

10. How can i debug a shared library using gdb..

11. debugging shared libraries using gdb

12. Help using gdb with shared libraries and child processes

13. Using 'ld' to build an ELF SHARED LIBRARY