Makefile pattern rule fails?

后端 未结 5 1044
春和景丽
春和景丽 2021-01-04 08:18

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 mak

5条回答
  •  旧时难觅i
    2021-01-04 08:38

    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 $<
    

提交回复
热议问题