Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between $< and $^ in a makefile?

Tags:

linux

makefile

What is the difference between the implicit variables $< and $^ in a makefile?

For example:

$(LIBS): $(LIB_OBJS)
        $(CC) $(CFLAG) -shared $< -o $@

and

$(LIBS): $(LIB_OBJS)
        $(CC) $(CFLAG) -shared $^ -o $@

It seems that the result is the same. In my case, I let $(LIBS) and $(LIB_OBJS) only have one file each.

like image 988
ChandlerKC Avatar asked Nov 19 '25 05:11

ChandlerKC


1 Answers

To quote from the GNU Make "Automatic Variables" page:

$<

The name of the first prerequisite. [...]

$^

The names of all the prerequisites, with spaces between them. [...]

So in your case when there is only one prerequisite there is no difference.

like image 162
Philip Kendall Avatar answered Nov 21 '25 19:11

Philip Kendall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!