next up previous
Next: Compiling a Single Source Up: Getting Started Previous: Getting Started

Compiling with GCC

A compiler turns human-readable source code into machine-readable object code that can actually run.The compilers of choice on Linux systems are all part of the GNU Compiler Collection, usually known as GCC. GCC also compiles Fortran (under the auspices of g77). Front-ends for Pascal, Modula-3, Ada 9X, and other languages are in various stages of development.The compilation process includes up to four stages: You can stop the process after any of these stages to examine the compiler's output at that stage.

GCC includes over 30 individual warnings and three "catch-all" warning levels. GCC is also a cross-compiler, so you can develop code on one processor architecture that will be run on another. Finally, GCC sports a long list of extensions to C and C++. Most of these extensions enhance performance, assist the compiler's efforts at code optimization, or make your job as a programmer easier. The price is portability, however.
This program will compute the reciprocal of an integer. http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/main.cmain.c

#include <stdio.h>
#include <stdlib.h>
#include "reciprocal.hpp"
int main (int argc, char **argv)
{
  int i;
  i = atoi (argv[1]);
  printf ("The reciprocal of %d is %g\n", i, reciprocal (i));
  return 0;
}
http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/reciprocal.cppreciprocal.cpp
#include <cassert>
#include "reciprocal.hpp"
double reciprocal (int i) {
// I should be non-zero.
assert (i != 0);
return 1.0/i;
}
There is also one header file called http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/reciprocal.hppreciprocal.hpp
#ifdef __cplusplus
extern "C" {
#endif
extern  double reciprocal (int i);
#ifdef __cplusplus
}
#endif
The first step is to turn the C and C++ source code into object code.

Subsections
next up previous
Next: Compiling a Single Source Up: Getting Started Previous: Getting Started
Cem Ozdogan 2007-02-19