Reputation: 2937
In a Makefile, I have a list of libraries I have to link against:
LIBS=var.a foo.a
I want to run the following command (simplified):
$(CC) main.c -lvar.a -lfoo.a
Now I use:
$(CC) main.c $(foreach lib,$(LIBS),-l$(lib))
It works, however it looks a bit wordy/cumbersome. Is there any better way to do it? Another approach?
Thanks!
Upvotes: 0
Views: 82
Reputation: 80921
One possible improvement is to use the addprefix
function.
$(addprefix -l,$(LIBS)
One could also use patsubst
$(patsubst %,-l%,$(LIBS))
Upvotes: 2