DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C compilation system

Compiling and linking

The C compilation system consists of a compiler, assembler, and link editor. The cc command invokes each of these components automatically unless you use command line options to specify otherwise. An executable C program is created with the following four steps:

  1. The preprocessor component of the compiler reads lines in your source files that direct it to replace a name with a token string (#define), perhaps conditionally (#if, for example). It also accepts directives in your source files to include the contents of a named file in your program (#include). Included header files for the most part consist of #define directives and declarations of external symbols, definitions and declarations that you want to make available to more than one source file. See ``Libraries and header files'' for details.

  2. The compiler proper, cc(CP), translates the C language code in your source files, which now contain the preprocessed contents of any included header files, into assembly language code.

  3. The assembler, as(CP), translates the assembly language code into the machine instructions of the computer your program is to run on. These instructions are stored in object files that correspond to each of your source files. Each object file contains a binary representation of the C language code in the corresponding source file. Object files are made up of sections, of which there are usually at least two. The text section consists mainly of program instructions. Text sections normally have read and execute, but not write, permissions. Data sections normally have read, write, and execute permissions.

  4. See ``Common Object File Format (COFF)'', and ``ELF object files'' for details of the supported object file formats.

  5. The link editor, ld(CP) links these object files with each other and with any library functions that you have called in your program. The link editing model you have chosen determines when the library functions are linked:

See ``Link editing'' for more information on how statically and dynamically linked libraries are implemented, and details on how to combine the static and dynamic linking approaches in different ways according to your needs.


NOTE: You can build dynamically linked libraries only for ELF binaries. See ``Shared libraries'' for more information on how to build a statically shared library in COFF file format.

``Organization of C Compilation System'' shows the organization of the C compilation system. Details concerning the optimizer are omitted here because it is optional. See ``Commonly used cc command line options'' for more information concerning invoking the optimizer.

Organization of C Compilation System



Next topic: Basic cc command line syntax
Previous topic: C compilation system

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003