Compiling Multi-File Programs

This process is rather more involved than compiling a single file program. Imagine a program in three files prog.c, containing main(), func1.c and func2.c. The simplest method of compilation (to produce a runnable file called a.out) would be

  cc prog.c func1.c func2.c

If we wanted to call the runnable file prog we would have to type

  cc prog.c func1.c func2.c -o prog

In these examples, each of the .c files is compiled, and then they are automatically linked together using a program called the loader ld.

  Go to organisation of data     Go to Index               Go to Separate Compilation