A source program consists of at least one source file. You can compile a source program that consists of several source files by specifying all of the source files as input to the compiler invocation command. Typically, compiler invocation produces calls to both the compiler and the linkage editor, and creates a single executable file as output. For example, to produce an executable file named testprog from three files, testdata.c, testres.c, and testparm.c, you would enter:
xlC testdata.c testres.c testparm.c -o testprog
You can also compile each source file separately by specifying the -c compiler option to invoke only the compiler to produce object files (.o files). You can then link-edit the resulting object files to create an executable file by invoking the compiler on these .o files without using the -c option.
For example, to produce object files for each of three programs, testdata.c, testres.c, and testparm.c, you would enter:
xlC testdata.c testres.c testparm.c -c
Then, to produce an executable file named testprog from these three object files, testdata.o, testres.o, and testparm.o, enter:
xlC testdata.o testres.o testparm.o -o testprog
To combine several source files at compilation, you can list the files on the command line when you use an invocation command to produce a compiled file for each file you specify. Or you can use the #include preprocessor directive to include the files in the primary source file so that one compiled file is produced. This directive causes the text of a named secondary source file to be imbedded at the point where the #include is encountered in the primary file.
Internal Structure of a C or C++ Program