CC(1,C) AIX Commands Reference CC(1,C)
-------------------------------------------------------------------------------
cc
PURPOSE
Compiles C programs.
SYNTAX
+-------------+ +----------------+ +--------------+
| one of | | +----------+ | | |
cc --| +---------+ |-| | -g -pg | |-| |-->
+-| -c -S |-+ +--| -G -w |--+ +-- -Hoption --+
| -E -X | ^ | -O -z | | ^ |
| -P | | | -p | | +------------+
+---------+ | +----------+ |
+--------------+
+--------------+ +----------+ +------------------------+
>--| +--------+ |-| |-|2 |-->
+--| -oname |--+ +- -Dname -+ | d+ o1+ o4+ ddir |
^ | flag 1 | | | g+ o2+ v+ ename |
| +--------+ | | 1+ o3+ w- lname |
+------------+ +------------------------+
+--------------------------+ +---------+
>--| 3+-----------+ |---- file ---| 6 |-|
+- -F file --| |-+ ^ | +- -lkey -+
+- :stanza -+ +--------+
-----------------
1 Use any flag belonging to as, cpp, or ld (except -l key).
2 These options are available on PS/2 only.
3 No space between these items.
6 Put this flag last if used (see the ld command).
DESCRIPTION
The cc command runs the C compiler. It accepts files containing C source code,
assembler source code, or object code and changes them into a form that the
operating system can run. cc compiles and assembles source files and then
links them with any specified object files, in the order listed on the command
line. It puts the resulting executable program in a file named a.out.
Running cc on an AIX PS/2 machine will generate an executable program that will
run on any AIX PS/2 machine. Similarly, running cc on an AIX/370 machine will
generate an executable program that will run on any AIX/370 machine. By
default, an AIX/370 program so compiled cannot make use of the extended
(31-bit) addressing mode of XA370 machines. To build an XA370 executable
program, use the -Hxa flag.
Processed November 8, 1990 CC(1,C) 1
CC(1,C) AIX Commands Reference CC(1,C)
If both the C Language and the Extended C Language compiler are installed on a
PS/2, the Extended C compiler is invoked by default. The C compiler is invoked
only if the COMPILER environment variable is set to "VSC". If only one
compiler is installed on a PS/2, /bin/cc invokes that C compiler.
The cc command uses the cc.cfg configuration file, which specifies the standard
runtime options, the link options, and the libraries to be used with each
version of the compiler.
For Berkeley Compability: When porting an application program from a 4.3 BSD
UNIX system to AIX, it can be useful to link with the Berkeley Compatibility
library. This library provides routines which more closely resemble the
behavior of a 4.3 BSD system. To provide this link, define the BSD environment
variable in your shell before running cc. Defining this variable instructs cc
to place the command line flags -D_BSD and -lbsd on your command line when
using cc. For more information on BSD compatibility, see BSD4.3 Library in the
AIX Technical Reference.
Input File Types
The cc command recognizes and accepts as input the following file types:
file.c The name of a C-language source file should end with .c. After cc
compiles this source file, it gives the resulting object file the same
name, except that it ends in .o rather than .c. If you use one command
both to compile and to load a single C program, the compiler normally
deletes the .o file when it loads the program. If you use the -c flag
or compile multiple files, the compiler does not delete the .o files.
file.i The name of a file that contains preprocessed C source code ends in .i.
file.o The name of an object file should end in .o. The cc command sends these
files to the ld command.
file.s The name of an assembly language source program should end with .s.
After cc assembles this source file, it gives the resulting object file
the same name, except that it ends in .o rather than .s.
FLAGS
The cc command recognizes several flags. In addition, flags intended to modify
the action of the linkage editor (ld), the assembler (as), or the preprocessor
(cpp) may also appear on the cc command line. cc sends any flags it does not
recognize to these commands for processing. The following list includes the
most commonly used cpp flags (-D, -I), and ld flags (-l, -L, -o). See "as,"
"cpp," and "ld" for a complete list of additional flags.
Processed November 8, 1990 CC(1,C) 2
CC(1,C) AIX Commands Reference CC(1,C)
Notes:
1. If you use the -l flag, it must be the last entry on the command line,
following any file parameters.
2. Do not use the -H options on the C Language compiler. All -H options are
Extended C Language-specific.
Ordinary Operation
-c Does not send the completed object file to the ld command. With
this flag, the output of cc is a .o file for each .c or .s file.
-Dname[=def]
Defines name as in a #define directive. The default def is 1.
-F file [:stanza]
Uses an alternative file and/or stanza for cc configuration. See
the AIX Operating System Technical Reference for a discussion of
the configuration file, cc.cfg.
-Hansi Causes the compiler to accept only programs conforming to the
proposed ANSI Standard. When you use the -Hansi option, you must
also use the -Hnoccp option.
-Hanno Used in conjunction with the -S option. Specifies that the
generated .s file is to be annotated with lines from the source
file. In some cases, the annotated lines from the source file are
not located immediately adjacent to the corresponding assembly code
generated in the .s file.
-Hasm Directs the compiler to produce a (pseudo-) assembly listing of the
generated code on standard output, by initializing the Asm toggle
to On. The assembly listing is annotated with lines from the main
source file, but not with lines from any included files. These
lines appear as comments immediately preceding the corresponding
assembly instructions. If the -S option (described below) is also
specified, the generated .s file is annotated with lines from the
source file, and no listing is written on standard output; for
example, it has the same effect as -Hanno.
-Hcpp Specifies that the outboard C macro preprocessor (/lib/cpp) is to
be used. -Hcpp is the default -H option. The preprocessor symbol
__STDC__ is defined only if -Hpcc is not specified and -Hnocpp is
specified. When the -P or -E flag is used, the -Hcpp option is
assumed.
-Hnocpp Specifies the use of the inboard C macro preprocessor. The
preprocessor symbol __STDC__ is defined only if -Hnocpp is
specified and -Hpcc is not specified. When the -P or -E flag is
used, the -Hcpp option is assumed.
Processed November 8, 1990 CC(1,C) 3
CC(1,C) AIX Commands Reference CC(1,C)
-Hfsingle Specifies that single-precision arithmetic is to be used in
computations involving only float expressions. That is,
floating-point operations are not to be performed in double
precision, which is the default. Non-prototyped functions declared
to return float may actually return double, depending on the
setting of the toggle Double_return. Some programs run much faster
with this option, but beware of loss of significance due to
lower-precision intermediate computations.
-Hlines=n Causes a page eject to occur after every n lines written to
standard output. The default of 60 is appropriate for most
6-lines-per-inch printers, which allow a maximum of 66 lines per
page for 11-inch paper. The setting of -Hlines is intended to
allow some blank space at page boundaries. For 8-lines-per-inch
(88 lines per page) printers, -Hlines should be set to 80 or 82.
This option is used in conjunction with the -Hlist and -Hasm
options. If n is 0, no page ejects are emitted.
-Hlist Causes the compiler to generate a source listing on standard
output. It works by initializing the List toggle to On.
-Hxa Generates load modules to run on XA-machines link-edit (ed) flag.
Note: When you are running on an XA machine, you should specify
the -Hxa option. If this option is not used, the space
available for allocation by the sbrk system call and malloc
subroutine is limited to 5 Mb (which would be 500 Mb when
-Hxa is specified) and 32-bit addresses are truncated to 24
bits.
-Hon=toggle
-Hoff=toggle
Turns a toggle On or Off. See the AIX Operating System C Using
Guide.
-Hpcc Specifies that the compiler is to run in "PCC" mode. In this mode,
the compiler relaxes enough of the ANSI extensions to more or less
emulate the Portable C Compiler. This permits old C programs that
would not ordinarily compile to compile with little (if any)
modification.
-H+w Issues all warnings by turning off the PCC_msgs toggle.
-E Runs the named C source file through only the preprocessor and
writes the result to standard output. The option works the same as
-P except -E writes to standard output. Specifying -P means that
-Hcpp is assumed and the outboard preprocessor is used even if
-Hnocpp is specified.
Processed November 8, 1990 CC(1,C) 4
CC(1,C) AIX Commands Reference CC(1,C)
-g Produces additional information for use with the dbx command (the
symbolic debugger).
-G Indicates that global variables are volatile. The optimizer makes
fewer transformations when you specify this flag. To make a
particular variable volatile, add the "volatile" specification to
its declaration. The -G option is supported by the C compiler
only.
-Idir Looks first in dir, then looks in the directories on the standard
list for #include files with names that do not begin with /
(slash).
-lkey Searches the specified library file, where key selects the file
libkey.a.ld searches for this file in the directory specified by an
-L flag, then in /lib and /usr/lib. The ld command searches
library files in the order in which you list them on the command
line.
-Ldir Looks in dir for files specified by -l keys. If it does not find
the file in dir, ld searches the standard directories.
-oname Assigns name rather than a.out to the output file.
-O Turns on the code optimizers.
-p Prepares the program so that the prof command can generate an
execution profile. The compiler produces code that counts the
number of times each routine is called. If programs are sent to
ld, the compiler replaces the startup routine with one that calls
the monitor subroutine at the start (see AIX Operating System
Technical Reference for a discussion of this subroutine), and
writes a mon.out file when the program ends normally.
-P Sends the specified C source file to the macro preprocessor and
stores the output in a .i file. Specifying -P means that -Hcpp is
assumed and the outboard preprocessor is used even if -Hnocpp is
specified.
-pg Causes the compiler to produce counting code in the manner of -p,
but invokes a run-time recording mechanism that keeps more
extensive statistics and produces a gmon.out file at normal
termination. Also, a profiling library is searched, in lieu of the
standard C library. An execution profile can be generated by use
of gprof (1, C) C Language compiler only.
-S Compiles the specified C programs, storing assembly language output
in a .s file.
-w Prevents printing of warning messages.
Processed November 8, 1990 CC(1,C) 5
CC(1,C) AIX Commands Reference CC(1,C)
-X Generates an assembly listing to standard output. (This option is
available with the C Language compiler only.)
-z This option is available only with the C Language compiler. Uses
the libm.a version, or a version specified by the user, of the
following transcendental functions:
acos asin atan atan2 cos exp
log log10 sin sqrt tan
If this flag is not used, the compiler generates inline
instructions for the 80387 math co-processor. For more information
on libm.a, see math.h in AIX Operating System Technical Reference.
PS/2 Specific Options
The AIX PS/2 C Language Compiler-specific options are described below. They
indicate which features are enabled or disabled when the compiler is invoked.
The options are described in alphabetical order.
b+ Floating Point Computation
Instructs the compiler to promote all floating-point values to double
precision before all floating-point computations.
d+ Disassembler Information
Produces additional information for use with the dis command (the
disassembler).
Note: With this option, you can also use the dbx command (symbolic
debugger). (See the g+ option below.) However, the .d file
does not contain symbolic information; therefore, you can only
do machine level debugging.
efilename
Error File
Instructs the compiler to place its error output in the file specified
by filename. If the filename option is not specified, error messages
are written to the standard error device.
g+ Debugger Information
Produces additional information for use with the dbx command (the
symbolic debugger).
Processed November 8, 1990 CC(1,C) 6
CC(1,C) AIX Commands Reference CC(1,C)
Notes:
1. With this option, you can also use the dis command disassembler),
see the d+ option above. However, allocation of variables into
registers is turned off.
2. If both the d+ and the g+ command-line options are set, regardless
of their order on the command line, the g+ option has the higher
priority.
3. The optimization process is disabled whenever the g+ option is
specified on the command line.
lfilename
Listing File
Instructs the compiler to place its listing output in the file
specified by filename. If the lfilename option is not specified, a
listing file is not generated.
l+ List to Standard Output Device
Instructs the compiler to generate a listing to the standard output
device.
o1+ Optimization Level 1
Instructs the compiler to use optimization level 1.
o2+ Optimization Level 2
Instructs the compiler to use optimization level 2.
o3+ Optimization Level 3
Instructs the compiler to use optimization level 3.
o4+ Optimization Level 4
Instructs the compiler to use optimization level 4.
v+ Compiler Progress Information
Instructs the compiler to generate information on the progress of the
compile.
w- No Warning Messages
Instructs the compiler not to generate warning messages.
Debugging
Processed November 8, 1990 CC(1,C) 7
CC(1,C) AIX Commands Reference CC(1,C)
-v Displays the trace as with -# and invokes the programs.
-# Displays a trace of the actions to be taken (for example, invoking
the preprocessor), without actually invoking any programs.
Extended Functions
C Language compiler only
-Bprefix Constructs path names for substitute preprocessor, compiler,
optimizer, assembler, or linkage editor programs. prefix defines
part of a path name to the new programs. To form the complete path
name for each new program, cc adds prefix to the standard program
names. For example, if you enter the command:
cc testfile.c -B/usr/bob/new
cc calls the following compiler programs:
1. /usr/bob/newcpp
2. /usr/bob/newvsc
3. /usr/bob/newvspass2
4. /usr/bob/newvspass3
5. /usr/bob/newas
6. /usr/bob/newld
Similarly, if you enter the command:
cc testfile.c -B/usr/bob/new/
cc calls the following compiler programs:
1. /usr/bob/new/cpp
2. /usr/bob/new/vsc
3. /usr/bob/new/vspass2
4. /usr/bob/new/vspass3
5. /usr/bob/new/as
6. /usr/bob/new/ld
The default prefix is /lib/o.
-t[pcgfal]
Applies the -B flag instructions for constructing file names to only
the designated preprocessor (p), compiler first (c), compiler second
(g), compiler third (f), assembler (a), or linkage editor (l) passes.
You can select any combination of pcgfal.
The -t flag with no additional p, c, g, f, a, or l designates by
default the preprocessor and compiler programs. If you do not
specify the -B flag when you specify the -t flag, the default file
name prefix is /lib/n.
Processed November 8, 1990 CC(1,C) 8
CC(1,C) AIX Commands Reference CC(1,C)
Note: You can specify this prefix with the -B flag. However,
depending on what combination of the -B and the -t flags you
specify, prefix can have two possible default values. If you
specify -B but no accompanying prefix, the default prefix is
/lib/o. If you specify the -t flag without also specifying
the -B flag, the default prefix is /lib/n.
-Wc,flag1[,flag2...]
Gives the listed flags to the compiler program c; c can be any one of
the values [pcgfal] discussed with the -t flag. For example, since
both ld and as recognize a -o flag, use -W to specify the program to
which the flag is to be sent. That is, -Wl,-o sends it to ld.
-Wa,-o sends it to as.
EXAMPLES
1. To compile and link a C program, creating an executable a.out file:
cc pgm.c
2. To compile a program, producing an object file to be linked later:
cc -c pgm.c
This compiles "pgm.c" and produces an object file named "pgm".o.
3. To view the output of the macro preprocessor:
cc -P -c pgm.c
This creates a file named "pgm".i that contains the preprocessed program
text including comments. To view this file, use an editor or see "pg." cc
passes the -P and -c flags to the preprocessor. See "cpp" for more details
about them.
4. To predefine macro identifiers:
cc -DBUFFERSIZE=512 -DDEBUG pgm.c
This assigns "BUFFERSIZE" the value "512" and "DEBUG" the value "1" before
preprocessing. cc passes the -D flag to the preprocessor.
5. To use #include files located in nonstandard directories:
cc -I/u/bob/include pgm.c
This looks in the directory that contains "pgm.c" for the #include files
with names enclosed in double quotes ("" ""), then in "/u/bob/include", and
then in the standard directories. It looks in "/u/bob/include" for
#include file names enclosed in angle brackets ("< >"), then in the
standard directories. cc passes the -I flag to the preprocessor.
Processed November 8, 1990 CC(1,C) 9
CC(1,C) AIX Commands Reference CC(1,C)
6. To optimize the object code and produce assembler source code:
cc -S -O pgm.c
This uses the optimizing compiler (-O is minus, capital oh), and produces
assembler source code in a file named "pgm".s (-S).
FILES
file.c C source file.
file.i Preprocessed C source file.
file.o Object file.
file.s Assembler file.
a.out Linked output.
/etc/cc.cfg cc configuration file.
/tmp/ctm* Temporary.
/lib/cpp C preprocessor.
/bin/as Assembler.
/lib/ld Linkage editor.
/lib/crt0.o Runtime startoff.
/lib/mcrt0.o Runtime startoff for profiling.
/lib/libc.a Standard library.
/lib/libm.a Standard math library.
/lib/librts.a Runtime services.
/usr/include Standard directory for #include files.
RELATED INFORMATION
See the following commands: "as," "ld," "vs," "cpp" and "dbx, mdbx."
See the C compiler in AIX C Language Reference and AIX C Language User's Guide.
See the monitor subroutine and the a.out and cc.cfg files in AIX Operating
System Technical Reference.
Processed November 8, 1990 CC(1,C) 10