Home > Software design >  Why makefiles compiles with -c flag
Why makefiles compiles with -c flag

Time:05-21

screen of my makefile

as you can see in no rules I tell the makefile to compile with the -c flag but he does, can somebody explain me why?

CodePudding user response:

You do not have a rule to make a .o file from a .c file in your Makefile, so make uses its default rule:

%.o: %.c
    $(CC) $(CPPFLAGS) $(CFLAGS) -c $@ $*.c

CodePudding user response:

See the makefile manual on implicit rules:

Compiling C programs

n.o is made automatically from n.c with a recipe of the form ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’.

If you wish to avoid this, define an explicit rule.

  • Related