A library's header file (ends with the .h) doesn't contain function definitions. It contains things like:
- function declarations (aka prototypes)
- variables
- structs and type definitions
See this answer and watch this short for more info.
To use a library, you need to do 2 things:
include header file in which the functions, types, variables, etc you'd like to use are declared
a. if the header file is already in one of the directories that are searched during preprocessing (e.g.,
/usr/include/), use:#include <filename.h>b. otherwise (e.g., if the header file is in same directory as the source code file), use:
#include "filename.h"link the library's binary code to your program using
-l[library name]. E.g., to link the cs50 library, you should run:clang prog.c -lcs50 -o prog
Note that make on the CS50 Appliance automatically links the cs50 library for you. So you could just run:
make prog