Source subdirectories dependency problem at link stage

Mathias Puetz mpuetz at unm.edu
Mon Dec 13 17:24:10 GMT 1999


To the developers,

I encountered the following problem when I tried
to import one of my old C-projects into KDevelop (1.0beta4) :

The project consists of two libraries and one program
of which the latter is structured in several subdirectories.
The structure looks something like this

generic    : very basic library with all sorts of stuff
             needed by all of the rest
iolib      : library managing IO
             needed by all of the program
base       : core program functionality (needs generic/iolib)
modules    : module extension interface/library (needs base & generic)
mod1..modX : extension modules (needs modules/kernel/iolib & generic)

main.c     : obvious

The problem is that KDevelop cannot handle the dependencies between
the modules with it's build-libraries-for-subdirectories approach,
because at link stage the order in which you link the libraries
is important !

Kdevelop tries to link in the following order (don't know
exactly anymore, but it comes close)

gcc -o progname main.o ./generic/libgeneric.a ./iolib/libiolib.a \
./base/libbase.a ./modules/libmodules.a ./mod1/libmod1.a ...

However this order causes references to e.g. libgeneric.a in the
following libs to be unresolved. The link problems could be solved
be linking the libs in different order. I tried to rearrange the
order in which the subdirs are listed  in the project-file by hand
with no success: Whenever Kdevelop has to recreate the Makefile.am
file in the main project dir the same (not working) order of
libraries is reproduced. It's unclear to me on which algorithm
KDevelop orders the library inclusions at link stage ( I assume
there is none taking care of inter-dependencies).

The use of ranlib doesn't cure this problem, since ranlib only takes
care of object file inter-dependencies within a subdirectory.
The old Makefiles for this project linked all object-files of the
various subdirectories directly which allows the linker to find
all inter-dependencies. Thus I strongly suggest removing the
intermediate link stage to build libraries and link all the files
directly or introduce some way to specify the link order.
However the latter does not take care of circular dependencies
between subdir objects unless you link some modules in twice.

For now I can help myself be adding the libs to the linker
options manually with the correct order, but that's like writing
Makefiles by hand again (which we lazy guys all don't want, do we ?).
So think about this because I think it's a huge issue which for now
limits the usability of Kdevelop quite strongly at least for larger projects.
If you want to keep the intermediate link stage, because you don't
want to keep track of all the objectfiles for the final link you could
link everything into *one* huge library instead of several smaller ones.
On first sight this approach doesn't look very appealing however.

Cheers,
Mathias

 ______________
/              \
| Mathias Puetz \__________________________________
|                                                  \
| Advanced Materials Lab (University of New Mexico) \
| 1001 University SE, Albuquerque, NM 87106         |
|                         \|/                       |
| phone: (505)272-7132    -O-    fax: (505)272-7336 |
|                         /|\                       | 
|   \|/    email: mpuetz at alpha214.unm.edu    \|/    |
\___/o\________or puetz at mpip-mainz.mpg.de____/o\____/




More information about the KDevelop mailing list