ChandlerKC
ChandlerKC

Reputation: 87

What's the difference between $< and $^ in a 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.

Upvotes: 3

Views: 160

Answers (1)

Philip Kendall
Philip Kendall

Reputation: 4314

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.

Upvotes: 5

Related Questions