[Next] [Previous] [Up] [Top] [Contents] [Index]
Chapter 16: Software Development
cc (lower case) is the vendor-supplied C compiler command on all Fermilab-supported UNIX systems (except LINUX, where it is gcc). ANSI C compilers are the default on most Fermilab systems. To compile one or more C source files (filename.c), you run the cc utility. cc automatically invokes the link editor ld unless the option -c, which explicitly suppresses linking, is used.
All the Fermilab supported UNIX systems have good FORTRAN 77 compilers, which provide some minimal extensions. These compilers also recognize most DEC-supported VAX-FORTRAN extensions.
f77 is the FORTRAN compiler command on all Fermilab-supported UNIX systems (except LINUX, where it is g77). The f77 command controls both compilation and linking functions automatically using appropriate FORTRAN runtime libraries. f77 can produce object modules, partially linked objects, or executable programs, as appropriate. The option -c explicitly suppresses linking.
Note that on AIX, to get help on f77 you need to type man xlf rather than man f77.
UNIX compilers, including f77 and cc, generally use both filename extensions and the file content to determine how to handle the files listed on the command line. The commonly used extensions are:
For C
c C source, e.g., myfile.c
For FORTRAN
f FORTRAN source, e.g., myfile.f
For both
o object file, e.g., myfile.o
a archive library, e.g., mylib.a
executable image, e.g., myfile
For historical reasons the UNIX linkers produce by default an executable named a.out; the option -o filename is available to override this default.
We list here some basic compiling and linking examples. In these examples, we use a source file named foo.c, where c is the standard extension for C. In all instances shown here c can be directly replaced by f, and cc by f77, for FORTRAN.
... enter the command:
foo.o object module cc -c foo.c
foo executable from source cc -o foo foo.c
foo executable from source + object file cc -o foo foo.c myobj.o
foo executable from source + library cc -o foo foo.c $CERN_DIR/lib/libmathlib.a
foo executable from source + X11/Motif (standard system libraries) cc -o foo foo.c -lXm -lXt -lX11
The options used with the cc and f77 commands are discussed in later sections.
Most UNIX linkers process source, object and library files in the order that they occur on the command line. Backward library references, from a file to an earlier library, will not be satisfied, except under AIX. It may be necessary to list a library more than once for successful linking.
AIX loads the entire content of all libraries into memory, eliminating ordering problems, but potentially creating memory usage problems. [Missing image]Listing a library more than once is unnecessary, and positively undesirable under AIX.
You may wish to know which options are active for a given compilation, in order to verify that the defaults are what you expect. Each platform seems to provide this information somewhat differently:
Platform | Option | Result |
|---|---|---|
AIX | | Source listing with options, to file |
IRIX | | Options and other details, to |
OSF1 | | Source listing with options, to file |
SunOS | not available |
|
At each stage of compilation, any unrecognized command line options are passed on to the next stage. Options that could be valid for more than one stage can be explicitly passed to a particular stage. To direct an option to a specific phase of compilation or linking, use the option -W (for AIX, IRIX, OSF1) or -Qoption (for SunOS). The phase is identified by the letter immediately following the -W. Thus, for example, -Wl,-m tells f77 or cc to pass the option string -m to the l (link) phase. The f77 command line might read:
% f77 -Wl,-m foo.f for AIX, IRIX, or OSF1, and
% f77 -Qoption ld -m foo.f for SunOS (where ld is the loader program)