> 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