Sometimes the user wants to link other libraries with his programs. A very common example is the use of the math library, which is not linked by default. Consider the following program:
#include <stdio.h> #include <math.h> int main(void) { printf("sqrt(17.0) = %f\n", sqrt(17.0)); return 0; }
A Makefile
for this program would look something like:
SOURCES = example.c OBJECTS = $(SOURCES:%.c=%.o) LIBRARIES = -lm CC = gcc CFLAGS = -O2 -ansi -pedantic -Wall %.o: %.c $(CC) -c $(CFLAGS)