|Department of Engineering|
|University of Cambridge > Engineering Department > computing help|
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'.
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.
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.
|| computing help ||