Compiling Fortran and C programs
Last revision August 4, 2004
Table of Contents:
|
cc is the C language compiler and linker
There is actually more than one C compiler on pangea. The standard cc name refers to the Compaq (vendor-supplied) compiler. We also have the GNU (Free Software Foundation) compiler under the name gcc. Each compiler has a separate, very detailed, on-line manual entry.
cc
The Compaq (formerly DEC) C Compiler which implements the ANSI Standard C syntax
of 1989. By default, it also allows traditional Kernighan and Ritchie syntax that
is not actually part of the ANSI C standard. Options permit or deny various extensions
to the C language, including extensions originally developed for VAX/VMS C. The
Compaq C compiler will also compile C++ programs if called by the name cxx.
gcc
The GNU C compiler. This is a public domain ANSI Standard C compiler developed
by the Free Software Foundation and supported and improved by the voluntary efforts
of many programmers around the world. It is available in versions for almost all
modern computer systems and is thus more "standard" than any other C compiler.
Because it has been widely used on many different architectures, many programmers
believe that it has been better tested and has fewer bugs than compilers provided
by vendors (like Compaq). Vendors counter that their compilers, because they are
written for a specific architecture, will produce more efficient code that runs
faster. If your C programs do not compile properly with the cc compiler,
try gcc. The GNU C compiler will also compile C++ programs if called
by the name g++.
The basic syntax to use the C compiler is:
cc [options] file(s)
More than one file can be specified; each is processed in turn. Specifications of options and files on the command line can be mixed; all options do not have to come first.
To compile source code into object code, make sure filenames end in .c. A resulting object code module is written to disk in the current directory with a filename the same as the input source code, except that a .o suffix is substituted for the .c suffix of the source.
cc automatically calls the macro preprocessor to process #include and #define statements in the source file.
If the filenames on the command line to cc refer to existing object code (.o) files, then cc automatically calls the ld program to link the final program. This automatic linking also occurs if one (but no more than one) of the file names on the command line is a source code (.c) file and the others (if any) are object code files.
The resulting executable program is given the name a.out in the
current directory by default. To save the program with another name, use the -o
option followed by the desired name, for example:
cc -o bigsim bigsim.c subs.o
When automatic linking is in effect, you can specify linker options on the cc command line and they will be passed on to the linker (see manual page for the ld program).
To prevent this automatic linking, use the -c option, for example:
cc -c bigsim.c
This makes the bigsim.o file but does not try to link it into an executable program.
Other commonly used options, found in all C compilers:
| -g | Produce symbol table information for the debugger dbx to use. |
| -O | (This option is the uppercase letter "oh", not the
numeral zero). Request optimization of the object code for faster execution; should
be done only after the program is debugged. On pangea, you can request various
"levels" of optimization for the Compaq cc compiler, specifically:
See the compiler manual entries for a description of the optimizations that are attempted at each level. |
Each C compiler has many additional options for more advanced tuning of the syntax it allows or the optimizations it attempts. These options vary from compiler to compiler. You must read the on-line manual entries for descriptions and definitions. The following options for the Compaq cc compiler on pangea are particularly useful.
-std0
Use the old (pre-1989) Kernighan and Ritchie C language syntax. This is useful
to compile very old C programs that were written before the ANSI C language standard
was created in 1989.
-taso
Compile to use only 32 bit addresses. Pangea has a true 64 bit processor and operating
system. That means that addresses, including pointers, are normally 64 bits. Most
previous Unix systems used 32 bit addresses. Some C programs that were written
for 32 bit machines may fail to compile or execute properly on a 64 bit machine
without extensive "porting" or modification. In those cases, you can usually compile
and use the program if you request the -taso flag.
-migrate
Support language extensions and compiler features that were available in the Compaq
(formerly DEC) C compiler on Ultrix (the old pangea system, now gondwana). Useful
when moving programs from Ultrix to Tru64 (formerly Digital) Unix.
-non_shared
By default, Tru64 (formerly Digital) Unix on pangea uses shared system libraries.
That means that system routines (e.g., input/output) are not actually included
within your compiled program. Instead, they are loaded at execution time. This
saves both disk space and memory. However, if you wish to use the compiled program
on another Tru64 Unix system, you may want to include those system libraries into
the program itself in case they differ on the other system. The -non_shared
flag will include all needed external library procedures directly into the final
executable program.