Make dependencies

Make dependencies

Post by Bob Greschk » Thu, 08 Nov 2001 00:37:25



I have a collection of C functions that I compile into a .a library
(e.g. lib.a)
I then write a program that links the lib.a file in when it is
compiled.

How do I tell make that the program needs to be recompiled if lib.a
changes?  Everything I try ends up giving me the error "No rule to
make target lib.a", which is true.  The program's makefile doesn't
know how to make the library, nor would I want it to.  I just want it
to recompile (just relink in this case) the program when the library
has been changed.

Thanks!

Bob

 
 
 

Make dependencies

Post by Shane McDanie » Thu, 08 Nov 2001 01:38:13



> I have a collection of C functions that I compile into a .a library
> (e.g. lib.a)
> I then write a program that links the lib.a file in when it is
> compiled.

> How do I tell make that the program needs to be recompiled if lib.a
> changes?  Everything I try ends up giving me the error "No rule to
> make target lib.a", which is true.  The program's makefile doesn't
> know how to make the library, nor would I want it to.  I just want it
> to recompile (just relink in this case) the program when the library
> has been changed.

> Thanks!

> Bob

Not actually seeing your make file, the typical way I know is to add it to
the depenency list

main: main.cpp main.h lib.a
        $(CC) ........

 
 
 

Make dependencies

Post by Paul D. Smit » Thu, 08 Nov 2001 01:50:41



  bg> I have a collection of C functions that I compile into a .a
  bg> library (e.g. lib.a) I then write a program that links the lib.a
  bg> file in when it is compiled.

  bg> How do I tell make that the program needs to be recompiled if
  bg> lib.a changes?  Everything I try ends up giving me the error "No
  bg> rule to make target lib.a", which is true.  The program's makefile
  bg> doesn't know how to make the library, nor would I want it to.  I
  bg> just want it to recompile (just relink in this case) the program
  bg> when the library has been changed.

If make doesn't know how to create a prerequisite, but the prerequisite
already exists, then that is good enough for make.

So, if you have written something like:

  program: lib.a

and you get an error "No rule to make target lib.a", that means that the
file "lib.a" doesn't exist.  If you don't provide a rule to build it,
then you _must_ make sure it exists before make needs to use it.

Without a concrete example I can't say for sure, but offhand I suspect
you aren't including the full or correct pathname to your library in the
prerequisite list; if the library is really in the ../mylib directory,
then you need to tell make that (else how could make know whether it's
newer than the target?)

  program: ../mylib/lib.a

Obviously it's probably best to make liberal use of variables,
etc. rather than hardcoding all these values.

--
-------------------------------------------------------------------------------

 http://www.gnu.org                      http://www.paulandlesley.org/gmake/
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

 
 
 

Make dependencies

Post by Bob Greschk » Thu, 08 Nov 2001 07:12:51


Hi!

That's what I was doing, but it turns out that the library Makefiles
were making libraries with names just slightly different than what
they were supposed to be and I didn't notice what was going on.  Ack!

Thanks!

Bob


.


> > I have a collection of C functions that I compile into a .a
library
> > (e.g. lib.a)
> > I then write a program that links the lib.a file in when it is
> > compiled.

> > How do I tell make that the program needs to be recompiled if
lib.a
> > changes?  Everything I try ends up giving me the error "No rule to
> > make target lib.a", which is true.  The program's makefile doesn't
> > know how to make the library, nor would I want it to.  I just want
it
> > to recompile (just relink in this case) the program when the
library
> > has been changed.

> > Thanks!

> > Bob

> Not actually seeing your make file, the typical way I know is to add
it to
> the depenency list

> main: main.cpp main.h lib.a
> $(CC) ........