This Gist presents an introduction to a few different ways of working with multiple source files in C, including:
- Simple
.c
source files and.h
header files compiled into a.exe
- First compiling into
.o
object files, and then linking together - Makefiles
- Statically linked libraries
- Dynamically linked libraries
The concepts are demonstrated using gcc (tdm64-1) 5.1.0
on Windows 8.1, using 3 C source files (linkedlist.c
, listprimes.c
and main.c
) and 2 header files (linkedlist.h
and listprimes.h
), all of which are included at the end. It is assumed that all the source files are saved in a single directory, and any terminal commands are entered in a terminal window open in that same directory.