I am seeing a line of makefile as follows:

$(LAST_TARGET_DIR)/%: LFLAGS += -lpthread -lrt -Wl,-uevaluate

In my understanding, $(LAST_TARGET_DIR)/% is a target matching, and after the target should come its dependencies. Why are linking flags changed here?

1 Answer 1


This is a feature of GNU make that allows using a different value of a variable for one specific target or pattern.

For example,

LFLAGS = -lm
$(LAST_TARGET_DIR)/%: LFLAGS += -lpthread

%.exe: %.o common.o
    $(CC) -o $@ common.o $(@:%.exe=%.o) $(LFLAGS)

causes every .exe file to be linked with -lm, except that those in the directory $(LAST_TARGET_DIR) will be linked with -lm -lpthreads.

  • Great. Thanks. GNU make is not an easy system :(
    – Ziqi Fan
    Dec 10, 2021 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.