how to find lib dependencies of exes

how to find lib dependencies of exes

Post by pan » Mon, 12 Oct 1998 04:00:00



I have joined a large software development, with poorly written makefiles.
Over ten executables, and over a hundred static libraries. Some of the
makefiles
for executables specify far more libraries than necessary to link against.

Is there a quick way, by either a single command, or a shellscript, to find
out the
exact list of libraries, an executable depends on? By this I just mean user
developed
libraries, not libraries like the standard c library etc. Or is the only
way to use trial and error by continually editing the library list in the
makefile and trying to link.

We have Solaris 2.5, the latest 4.2 C/C++ compiler and whole SunWorkshop
suite
of development tools.

I also have another question about linkage. Can someone explain what is
mean by
'circular references'? If a library contains a symbol that requires another
library to resolve it, and the other library also requires the first
library - is that it?

I don't get why I have to sometimes specify the same library twice  to get
an
executable to link. I would have thought that the Sun linker is good enough
to
avoid having to put these kind of hacks into your makefile. Is there a way
to tell
it to do more passes, rather that having to bodge things by specifying the
same
library twice?

Thanks for any advice.

 
 
 

how to find lib dependencies of exes

Post by RaoulReye » Mon, 12 Oct 1998 04:00:00


This might be stupid but have you tried ldd?

 
 
 

how to find lib dependencies of exes

Post by Harald Kirs » Mon, 12 Oct 1998 04:00:00



> Is there a quick way, by either a single command, or a shellscript, to find
> out the
> exact list of libraries, an executable depends on? By this I just mean user
> developed
> libraries, not libraries like the standard c library etc. Or is the only
> way to use trial and error by continually editing the library list in the
> makefile and trying to link.

If nobody comes up with a better idea, your last resort will be the
command `nm', which shows the symbols in an object file. Those tagged
`U' are undefined, those tagged 'T' are defined. It is up to you to
write a <your favorite scripting language here>-script to match the Us
of your executables with the Ts of the user libraries.

Quote:> I don't get why I have to sometimes specify the same library twice  to get
> an
> executable to link. I would have thought that the Sun linker is good enough
> to
> avoid having to put these kind of hacks into your makefile.

I am about a year out of Solaris (now on Linux :-), but AFAIR the
linker _is not good enough_ and you have to specify twice.

        Harald Kirsch.
--
---------------------+------------------+--------------------------


              gegen Punktfilitis hilft nur `chmod u-w ~'

 
 
 

how to find lib dependencies of exes

Post by Ke Ji » Tue, 13 Oct 1998 04:00:00


try:

    ldd  on solaris, linux, dec, unixware, irix, ...
    chatr on hp
    dump -H on aix
    ....

good luck

Ke


> I have joined a large software development, with poorly written makefiles.
> Over ten executables, and over a hundred static libraries. Some of the
> makefiles
> for executables specify far more libraries than necessary to link against.

> Is there a quick way, by either a single command, or a shellscript, to find
> out the
> exact list of libraries, an executable depends on? By this I just mean user
> developed
> libraries, not libraries like the standard c library etc. Or is the only
> way to use trial and error by continually editing the library list in the
> makefile and trying to link.

> We have Solaris 2.5, the latest 4.2 C/C++ compiler and whole SunWorkshop
> suite
> of development tools.

> I also have another question about linkage. Can someone explain what is
> mean by
> 'circular references'? If a library contains a symbol that requires another
> library to resolve it, and the other library also requires the first
> library - is that it?

> I don't get why I have to sometimes specify the same library twice  to get
> an
> executable to link. I would have thought that the Sun linker is good enough
> to
> avoid having to put these kind of hacks into your makefile. Is there a way
> to tell
> it to do more passes, rather that having to bodge things by specifying the
> same
> library twice?

> Thanks for any advice.

--
Ke Jin

San Mateo, CA 94404               1+ (650) 258-2409
 
 
 

how to find lib dependencies of exes

Post by Rod Eva » Tue, 13 Oct 1998 04:00:00



Quote:>I have joined a large software development, with poorly written makefiles.
>Over ten executables, and over a hundred static libraries.
>Is there a quick way, by either a single command, or a shellscript, to find
>out the exact list of libraries, an executable depends on?

The link editors debugging can identify all input files used, including any
archive members:

        % LD_OPTIONS=-Dfiles cc -o main main.o -L. -la                
        .....
        debug: file=main.o  [ ET_REL ]
        debug: file=./liba.a  [ archive ]
        debug: file=/usr/lib/libc.so  [ ET_DYN ]

The above shows that no members were extracted from liba.a, on the otherhand:

        % LD_OPTIONS=-Dfiles cc -u a -o main main.o -L. -la
        .....
        debug: file=main.o  [ ET_REL ]
        ebug: file=./liba.a  [ archive ]
        debug: file=./liba.a(a.o)  [ ET_REL ]                <<<<-------
        debug: file=./liba.a  [ archive ] (again)
        debug: file=/usr/lib/libc.so  [ ET_DYN ]

shows that the archive member (a.o) was extracted to satisfy the reference `a'.
Note also the `(again)' cycle.  On extraction of a archive member the link-editor
will rescan the archive in case other objects satisfy references from the
extracted member.

Quote:>I also have another question about linkage. Can someone explain what is mean by
>'circular references'? If a library contains a symbol that requires another
>library to resolve it, and the other library also requires the first
>library - is that it?

>I don't get why I have to sometimes specify the same library twice  to get
>an executable to link. I would have thought that the Sun linker is good enough
>to avoid having to put these kind of hacks into your makefile. Is there a way
>to tell it to do more passes, rather that having to bodge things by specifying
>the same library twice?

If an archives members have circular dependencies there is no need to specify
the archive more than once, it will be rescanned until all references are found
that can be satisfied by the archive (see (again) discussion above).

If there exists circular dependencies between different archives they may need
to be scanned more than once.  The linker editor makes *one* pass of the input
files of the command line.  This is only true of archives.  Any shared object
referenced will have its entire symbol table processed when first read, and
thus later references can be satisfied without having to specify the shared object
again on the command line.

---

Rod.

 
 
 

how to find lib dependencies of exes

Post by Christopher Gree » Wed, 14 Oct 1998 04:00:00



> I have joined a large software development, with poorly written makefiles.
> Over ten executables, and over a hundred static libraries. Some of the
> makefiles
> for executables specify far more libraries than necessary to link against.

> Is there a quick way, by either a single command, or a shellscript, to find
> out the
> exact list of libraries, an executable depends on? By this I just mean user
> developed
> libraries, not libraries like the standard c library etc. Or is the only
> way to use trial and error by continually editing the library list in the
> makefile and trying to link.

"ldd" will tell you the shared libraries that contribute to the
executable.
If the libraries that concern you are all static, then "ldd" won't help.

You can cut down on the work involved by being systematic.

Working from the end of the library list toward the beginning, remove a
library, relink, and see what comes up undefined.  This is the simpler
way, because the only thing you have to look for is whether the link
command succeeds or fails.  A good shell programmer should be able to
automate this and just let it run overnight.

Or, working from the start of the library list toward the end, remove
a library, relink, and see what comes up undefined.  For each undefined
symbol, use "nm" to track down the library in which it is defined, and
mark that library as essential.  Repeat for the next library that has
not yet been marked essential, and so on, until you have marked all the
essential libraries and removed all the nonessential ones.

Quote:> We have Solaris 2.5, the latest 4.2 C/C++ compiler and whole SunWorkshop
> suite
> of development tools.

> I also have another question about linkage. Can someone explain what is
> mean by
> 'circular references'? If a library contains a symbol that requires another
> library to resolve it, and the other library also requires the first
> library - is that it?

With respect to libraries, that's a circularity.  The way you break such
a
circularity is by including one of the libraries twice.  That's legal,
though it's a dead giveaway that your libraries are badly organized.

Quote:> I don't get why I have to sometimes specify the same library twice  to get
> an
> executable to link. I would have thought that the Sun linker is good enough
> to
> avoid having to put these kind of hacks into your makefile. Is there a way
> to tell
> it to do more passes, rather that having to bodge things by specifying the
> same
> library twice?

The Sun linker behaves the same way almost all UNIX linkers do (the AIX
linker is the only exception I know).  Libraries are searched only once,
at the place they occur in the linker command.  If you have to specify a
library twice, it's because your libraries are a mess, not because the
linker has brain damage.

If you want to force particular object modules to be linked uncon-
ditionally, use "ar" to break them out of the libraries and link them
as .o files.  That's another way to break up circularities, but it can
make for very long linker commands.

Quote:> Thanks for any advice.

Good luck.  Large, disorganized projects are a chore to maintain, any
way you look at it.

--
Chris Green
Advanced Technology Center
Laguna Hills, California

 
 
 

how to find lib dependencies of exes

Post by Bob Tenne » Wed, 14 Oct 1998 04:00:00



 >
 >Is there a quick way, by either a single command, or a shellscript, to find
 >out the
 >exact list of libraries, an executable depends on?

If you have an executable called foo, do ldd foo.

Bob T.

 
 
 

1. /usr/lib/gcc-lib/i386-linux and /usr/lib/gcc-lib/i486-linux

Hi Linuxers,

I just got a new copy of gcc-2.4.5 and source code of the pl11.
After having done the installation of gcc-2.4.5, I realised that
I have an extra directory: /usr/lib/gcc-lib/i386-linux.
The question is whether I need to keep the old gcc stuff under
the i386-linux.  I really like to clean it up so as to save 5.1
meg disk space (another poor Linux user  ;-( ).

Your answer is very appreciated.  Please send answer directly
to my address or the corresponding interest parties to reduce
the network load.  Thank you in advance.

Wing



2. how to add a new disk to FreeBSD ?

3. Missing /usr/src/e2fsprogs-1.10/lib/ext2fs/ext2_err.h ?

4. Printing from Qt ...

5. help, apps finding libs in kde2/libs...??

6. KPPP disconecting at given time?

7. Anyone, who knows a lib that resolves dependencies?

8. who makes the best Linux? Microsoft?

9. symbol belongs to implicit dependency /usr/lib/libnsl.so.1

10. Gnome-lib dependencies and installing pan

11. install dependency lib

12. adding library dependency to existing shared lib

13. Broken lib dependencies in RedHat RPM's of Final Beta