Multi-File Programs
- C/C++ programs typically comprise multiple files
- A typical small program would have a header file,
an implementation file, and a client file
- The header file has a .h extension, and it
usually contains variable and function declarations
- More about header files...
- The implementation file has .C extension, and
it contains the variable and function definitions
- The client file also has a .C extension, and it
contains
the client functions that calls the functions in the implementation file.
Usually, this file contains the main() function.
- This multi-file structure has several advantages:
- Simplified organization of the program
- Reduction in compilation time because each file is compiled
separately
- Only those files that have been modified need be re-compiled
- Makes it easier to debug large programs
- The Process:
- Compile each source file separately using the -c compiler
option
- Link the object files to create one executable file
- Run the executable
- Example:
g++ -c function.C
g++ -c main_client.C
g++ function.o main_client.o
a.out
- This process can be automated using the UNIX make
utility
- More about variable and function
scope...
- Example of a multi-file program...
Back to Previous Page
Document:
Local Date:
Last Modified On: