Makefile help needed
David Kramer
david at thekramers.net
Sat Jul 2 02:16:32 EDT 2005
My makefile is *mostly* working.
My problem is this: I want to build a .o in a different directory from the
current one, and it's being rather stubborn unless I spell out the rule.
Imagine if you will, a makefile that can build target1, target2, and
target3, and I'm adding troubletarget.o to it. Assume troubletarget.c is in
the currect directory with everything else
If I do:
all: target1 target2 target3 troubletarget.o
it builds fine.
If I do:
all: target1 target2 target3 ./troubletarget.o
it builds fine.
If I do:
all: target1 target2 target3 ../otherdir/troubletarget.o
I get "make: *** No rule to make target ../otherdir/troubletarget.o"
which I can understand, because it doesn't know where the C file is.
HOWEVER, if I do:
all: target1 target2 target3 ../otherdir/troubletarget.o
it simply does not try to build it at all.
If I add a rule like:
../otherdir/troubletarget.o: troubletarget.c
it still doesn;t attempt to build it.
If I change that to
../otherdir/troubletarget.o: troubletarget.c
$(CC) $(CFLAGS) -c $< -o $@
it works, but I don't see why I have to do that, since it already knows how
to turn a .c into a .o, because earlier in the file I have
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
which should build it fine,
Note that I can't use the newer style
%.o : %.c ; command...
because the stem is different on the .o and the .c since they're in
different directories.
Does this make sense? What am I doing wrong? Thanks in advance.
More information about the Discuss
mailing list