What do $< and $@ represent in a Makefile?

前端 未结 2 1088
醉话见心
醉话见心 2020-12-05 16:13

Can anybody please explain the meaning of $< and $@ in a Makefile?

2条回答
  •  甜味超标
    2020-12-05 16:36

    $< evaluates to the first "prerequisite" in the make rule, and $@ evaluates to the "target" in the make rule.

    Here's an example:

    file.o : file.c
            $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
    

    In this case, $< will be replaced with file.c and $@ will be file.o.

    These are more useful in generic rules like this:

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

    See this manual for more info.

提交回复
热议问题