|
|
|||
![]() |
Department of Engineering |
| University of Cambridge > Engineering Department > computing help |
The Fortran77, Fortran9x, C and C++ compilers installed on the central system work in very similar ways. Creating an executable program from source code involves two main steps; compiling the source files to produce object code files, and linking the object files to form an executable file.
The names of Fortran source files by convention have the suffix .f or (for fortran 90) .f90, C source files have .c and C++ source files have .cc or .C.
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 languages mentioned above are as follows:
g++ -g -c firstprog.cc g++ -g -c secprog.cc g++ -g firstprog.o secprog.o -o complete_progThe -c flag makes the compiler generate .o files rather than attempting to create a complete executable program.
If you're writing a program that has many source files, it's worth learning about Makefiles (the Computing Service has a document about make or IDEs (Integrated Development Environments - anjuta might be installed, for example)
If a library is required by a program then this must be introduced at the linking stage using the -l flag. For example, to link in the X11 library the last command would be changed to
g++ -g firstprog.o secprog.o -o complete_prog -lX11For the C++ compiler we have a graphical front-end (xcc) that tries to add the appropriate options automatically, and copes with multiple source files.
| | computing help | Languages | |