automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Circular dependecy linker trouble


From: Bob Proulx
Subject: Re: Circular dependecy linker trouble
Date: Thu, 7 Jun 2007 14:45:58 -0600
User-agent: Mutt/1.5.9i

Søren Boll Overgaard wrote:
> Hello,
> 
> I've recently migrated a rather large body of code from a proprietary 
> development environment, to an automake based one.
> 
> I've run into trouble during linking though. The code is laid out like 
> this:
> 
> src/ 
> Contains main.cpp which holds the main method
> 
> src/framework/ 
> Contains framework code. All files in here are packed into an archive 
> libframework.a.
> 
> src/services/
> Contains service related code. All files in here are packed into an 
> archive libservices.a
> 
> No other programs need these archives, so I guess I could just as well 
> link with the object files directly, if I could determine a clean way of 
> doing that.

I would keep the libraries.  It encourages modularity.

> Framework code depends on services code and vice versa. 
> Linking fails to resolve dependencies.

Even if modularity is observed.  :-)

> The linker command line essentially looks like this:
> 
> g++  -g -O2 ../src/framework/libframework.a ../src/services/
> liblmsservices.a  -o program main.o  -lpthread

That is the new linker line, right?  What was the previous linker line
that you are replacing?  I expect that the libraries were listed
multiple times previously or it would not have worked with the prior
build system.

> Can anyone explain to me what I am doing wrong?

Effecitvely libraries are searched left to right and .o files are
pulled out of them as they are needed.  When circular dependencies
between .a files exist then you will need to list the .a files
multiple times on the link line so that they are processed more than
once.

Of course breaking the circular dependencies would be best but I
understand that this is legacy code and that you are moving forward
incrementally, a common practice.

I suggest using LDADD or PROG_LDADD (where PROG is the name of the
program as it appears in the _PROGRAMS variable, usually lower case)
and adding the libraries again there.  (Although if others on the list
suggest better things please go with their suggestions.)

Because you are already getting these libraries on the command line by
some means I think this following should work.

  LDADD = ../src/framework/libframework.a ../src/services/liblmsservices.a

If you were getting those libs onto the command line by that method
already then you need to double them so that they appear twice.

  LDADD = ../src/framework/libframework.a ../src/services/liblmsservices.a 
../src/framework/libframework.a ../src/services/liblmsservices.a

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]