A library's header file (the one that endsends with the .h extension) doesn't contain function definitions. Instead, itIt contains the library's resources that are available for you to use. These resources includethings like:
- Functionfunction declarations (aka prototypes).
- Variables.
- Structs.variables
- Typestructs and type definitions.
For more information, you may have a look at thisSee answerthis answer and watch the shortthis short on libraries - week 1!for more info.
To use a library, you haveneed to do 2 things:
To include the library's header file usingin which the functions, types, variables, etc you'd like to use are declared
a. In caseif the header file is already in one of the default include directorydirectories that are searched during preprocessing (i.e.g.,
/usr/include/) we, use:#include <filename.h>b. In case the header is not in the default include directoryotherwise (e.g., in case it's inif the header file is in same directory as the source code file or in another directory), we use:
#include "filename.h"To link the library's binary code with the binary code ofto your program using the
-l[library name]. For exampleE.g., to link the cs50 library, you may to compile your program like thatshould run:clang prog.c -lcs50 -o prog
NoticeNote that make on the applianceCS50 Appliance automatically links the cs50 library by defaultfor you. So you maycould just run:
make prog