Libraries#

C’s standard library is small and intentionally close to the operating system. Everything else comes from third-party libraries linked at build time.

Standard Headers#

  • <stdio.h> , formatted I/O (printf, fopen, fread)

  • <stdlib.h> , memory (malloc, free), conversions, exit

  • <string.h> , memcpy, strlen, strcmp, strncpy

  • <stdint.h> , fixed-width integer types

  • <stdbool.h>, bool, true, false

  • <math.h> , sin, cos, sqrt (link with -lm)

  • <time.h> , timestamps, clock_gettime

  • <errno.h> , errno codes from system calls

Linking a Library#

Headers are found on the include path; archives or shared objects are linked with -l:

$ cc main.c -o main -lm -lpthread

pkg-config#

Most third-party libraries ship a .pc file:

$ cc main.c $(pkg-config --cflags --libs libcurl) -o main

Useful Libraries#