I have a short question related to the purpose of this line in the Makefile of pset5 (spellchecker):

# space-separated list of libraries, if any,
# each of which should be prefixed with -l

I can't understand what's the difference between putting here, say -lcs50 against declaring it with #include <cs50.h>, for example, in either speller.c or dictionary.c. Is there any functional difference between the two? Thanks!

1 Answer 1


LIBS is a variable in the makefile. if you look at the lines

# default target
$(EXE): $(OBJS) $(HDRS) Makefile
    $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)

you can probably tell that it gets substituted with its value in the compilation command. this variable should contain any libraries you want to link (using the -l option).

when you include a header file (as in #include <cs50.h>), you're not linking the library's binary file. the former is a preprocessor directive that is processed by the preprocessor while the later is done using the -l option on compilation and is processed by the linker.

see https://youtu.be/CSZLNYF4Klo and https://youtu.be/ED7QtgXDShY!

this answer may help you too: https://cs50.stackexchange.com/a/1270/1161!

  • Kareem, you are so helpful. Thank you so much!
    – Xiggi
    Commented Jul 1, 2015 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .