totn C Language

C Language: Compiling and Linking

This C tutorial explains compiling and linking in the C language.

Description

C programs are written in human readable source code that is not directly executable by a computer. It takes a three step process to transform the source code into executable code. These three steps are: Preprocessing, compiling and linking.

  • Preprocessing - Processes directives (commands that begin with a # character) which can modify the source code before it is compiled.
  • Compiling - The modified source code is compiled into binary object code. This code is not yet executable.
  • Linking - The object code is combined with required supporting code to make an executable program. This step typically involves adding in any libraries that are required.

In most modern compilers, these three activities are handled by a single application although it is possible to tell the compiler not to do certain functions. (For example, to compile but not link a program.)

There are a variety of C compilers available for many different platforms. Some compilers must be purchased and some are free to use. Three of the most common are: GNU gcc, Clang/LLVM and Microsoft Visual C.

  • GNU gcc is found on many platforms such as Linux, many flavors of UNIX and even Windows.
  • Clang/LLVM is available for all modern Mac OSX systems and many BSD variants.
  • Microsoft Visual C is a core component in Microsoft's Visual Studio platform.

We will be using GNU gcc in our examples mainly due to its availability on many different platforms.