Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile pattern rule fails?

Tags:

gnu-make

While using GNU-make, my Makefile has some pattern rule as:

%.o:%.c
    gcc $< -o:$@

This rule is added by me.

But when I do make it gives an error saying No rule to make target %.o and doesn't build the targets.

At times, there is this other behaviour as well. It does not build the target when I say make first time(It gives error saying No rule to make target), but when i say make again immediately, it does build correctly.

So when i explicity specify each source file separately, then it builds the targets fine first time itself.

EDIT: I am using GNU-make on a Centos (v6.3 i guess, not sure). Could this be some permission/user id /group id issue?

Any pointers to understand what might be happening and solution for this?

thank you, -AD.

like image 352
goldenmean Avatar asked Mar 01 '11 14:03

goldenmean


1 Answers

If you put only this in a Makefile and call make:

%.o: %.cpp
  g++ -g -o $@ -c $<

It tells: make: *** No targets. Stop.

Because it's not a target. It's a rule.

It will work if your another target needs a .o file.

main.exe: main.o add.o
  g++ -g -o $@ $^

%.o: %.cpp
  g++ -g -o $@ -c $<
like image 68
mortalis Avatar answered Oct 27 '22 21:10

mortalis