Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Mail Up: Utilities Previous: Emacs using Control Keys

Compilers

The Fortran 90, C and C++ compilers work in very similar ways. Creating a program you can run from program text files involves two main steps; compiling the source files to produce object code files, and linking the object files to form an executable file.

Fortran 90 source files usually have the suffix `.f90', C source files have `.c', and C++ source files have `.cc'.

Compiling a Single Source File:-

If the program is contained in only one file then the compilation and linking together can be performed in one step. The commands for each of the three languages are as follows:

gcc myprog.c -o myprog

g++ myprog.cc -o myprog

g77 myprog.f -o myprog

The -o myprog instructs it to name the executable program myprog in each case. If the `-o' flag and its argument are not present the name of the executable is a.out.

Compiling Multiple Source Files:-

If the program is composed of several source files then these must be compiled individually to produce object files with the suffix `.o'. These `.o' files are then linked to generate the program complete_prog.

g++ -c firstprog.cc

g++ -c secprog.cc

g++ firstprog.o secprog.o -o complete_prog

The `-c' flag makes the compiler generate `.o' files rather than attempting to link the program to form a complete executable program.


next up previous contents
Next: Mail Up: Utilities Previous: Emacs using Control Keys
© Cambridge University Engineering Dept
Information provided by Tim Love
2005-08-22