cc(1)
NAME
cc − C compiler
SYNOPSIS
cc [ −# ] [ −### ] [ −Aname [(tokens) ] ] [ −B [static|dynamic] ] [ −C ]
[ −c ] [ −Dname [=token ] ] [ −d [y|n] ] [ −dalign ]
[ −E ] [ −fast ] [ −fd ] [ −flags ] [ −fnonstd ]
[ −fsimple ] [ −fsingle ] [ −fstore ] [ −G ] [ −g ] [ −H ]
[ −Idir ] [ −i ] [ −KPIC ] [ −Kpic ] [ −keeptmp ]
[ −Ldir ] [ −lname ] [ −mc ] [ −misalign ] [ −misalign2 ]
[ −mr ] [ −mr,string ] [ −mt ] [ −native ] [ −nofstore ]
[ −noqueue ] [ −O ] [ −o outputfile ] [ −P ] [ −p ] [ −Q [y|n] ]
[ −q [l|p] ] [ −Rdir[:dir] ] [ −S ] [ −s ] [ −Uname ] [ −V ] [ −v ]
[ −Wc,arg ] [ −w ] [ −X [a |c |s |t ]] [ −x386 ] [ −x486 ] [ −xa ]
[ −xCC ] [ −xcg89 ] [ −xcg92 ] [ −xe ] [ −xF ] [ −xinline=[f1,...,fn] ]
[ −xlibmieee ] [ −xlibmil ] [ −xlicinfo ] [ −xM ] [ −xM1 ] [ −xMerge ]
[ −xnolib ] [ −xnolibmil ] [ −xO[1,2,3,4] ] [ −xP ] [ −xpentium [ −xpg ]
[ −xs ] [ −xsb ] [ −xsbfast ] [ −xstrconst ] [ −xtime ] [ −xunroll =n ]
[ −Yc,dir ] [ −YA,dir ] [ −YI,dir ] [ −YP,dir ] [ −YS,dir ] [ −Z11 ] [ −Ztha ]
DESCRIPTION
The cc(1) manual page describes the ANSI C compiler options that are SVID compliant under Solaris 2.x. cc uses getopt to parse command line options. Options are treated as a single letter or as a single letter followed by an argument. See getopt(3c).
For a comparison of cc options in Sun C (Solaris 1.x), Sun ANSI C (Solaris 1.x), and ANSI C (SunOS/SVR4), see the C 3.0.1 Transition Guide for SPARC Systems .
cc is the interface to the C compilation system. The compilation tools conceptually consist of a preprocessor, compiler, code generator, optimizer, basic block analyzer, assembler, and link editor. cc processes the supplied options and then executes the various tools with the proper arguments. cc accepts several types of files as arguments.
Files whose names end with .c are taken to be C source files and may be preprocessed, compiled, optimized, instrumented for profiling, assembled, and link edited. Although the preprocessor can be used as a macro processor, this is not recommended, as its output is geared toward that which would be acceptable as input to a valid C compiler. The compilation process may be stopped after the completion of any pass if the appropriate options are supplied. If the compilation process runs through the assembler, then an object file is produced whose name is that of the source with .o substituted for .c. However, the .o file is normally deleted if a single C file is compiled and then immediately link edited. In the same way, files whose names end in .s are taken to be assembly source files; they may be assembled and link edited. Files whose names end in .i are taken to be preprocessed C source files, and they may be compiled, optimized, instrumented for profiling, assembled, and link edited. Files whose names do not end in .c, .s, or .i are handed to the link editor, which produces a dynamically linked executable whose name by default is a.out.
The following options are interpreted by cc:
−# Show each component as it is invoked (verbose mode).
−###
Show each component as it is invoked, but, unlike the −# option, do not actually execute.
−Aname[(tokens)]
Associate name as a predicate with the specified tokens as if by a #assert preprocessing directive.
Preassertions:system(unix)
cpu(sparc) (SPARC only)
machine(sparc) (SPARC only)
cpu(i386) (x86 only)
machine(i386) (x86 only)
The above are not predefined in −Xc mode.
If −A is followed by a dash (-) only, it causes all predefined macros (other than those that begin with __) and predefined assertions to be forgotten.
−B [static|dynamic]
−B dynamic causes the link editor to look for files named libx.so and then for files named libx.a when given the −lx option. −B static causes the link editor to look only for files named libx.a. This option may be specified multiple times on the command line as a toggle. This option and its argument are passed to ld.
−C Cause the preprocessor to pass along all comments other than those on preprocessing directive lines.
−c Suppress the link editing phase of the compilation and do not remove any produced object files.
−Dname[=token]
Associates name with the specified token as if by a #define preprocessing directive. If no =token is specified, the token 1 is supplied.
Predefinitions:unix
sparc (SPARC only)
i386 (x86 only)
sun
The above are not predefined in -Xc mode.
These predefinitions are valid in all modes:
__sparc (SPARC only)
__i386 (x86 only)
__unix
__sun
__BUILTIN_VA_ARG_INCR
__SUNPRO_C=0x301
__SVR4
−d [y|n]
−dy specifies dynamic linking, which is the default, in the link editor. −dn specifies static linking in the link editor. This option and its argument are passed to ld.
−dalign
(SPARC only) Generate double load/store instructions wherever possible for improved performance. Assume that all double-typed data are double aligned, and should not be used when correct alignment is not assured.
−E Preprocess only the named C files and send the result to the standard output. The output will contain preprocessing directives for use by the next pass of the compilation system.
−fast Select the optimum combination of compilation options for speed. This should provide close to the maximum performance for most realistic applications. Modules compiled with −fast , must also be linked with −fast .
It is a convenience option, and it chooses the fastest code generation option available on the compile-time hardware, the optimization level −xO2, a set of inline expansion templates, the −fnonstd floating-point option, the −dalign option, and it adds −lm to link in the math library.
If you combine −fast with other options, the last specification applies. The code generation option, the optimization level and using inline template files can be overridden by subsequent switches. For example, although the optimization part of −fast is −xO2, the optimization part of −fast -xO1 is −xO1.
Do not use this option for programs that depend on IEEE standard exception handling; you can get different numerical results, premature program termination, or unexpected SIGFPE signals.
−fd Reports old style function declarations and definitions.
−flags
Print a one-line summary of available options.
−fnonstd
Cause non-standard initialization of floating-point arithmetic hardware. By default, IEEE 754 floating-point arithmetic is nonstop, and underflows are gradual. The −fnonstd option causes hardware traps to be enabled for floating-point overflows, division by zero, and invalid operation exceptions. These are converted into SIGFPE signals, and if the program has no SIGFPE handler, it will terminate with a memory dump (see ieee_handler(3m)). −fnonstd also causes the math library to be linked in (by passing −lm to the linker).
−fsimple
Simple floating-point model. Allow optimization using mathematically equivalent expressions. The optimizer is allowed to act as if a simple floating-point model holds during compilation and runtime. It is allowed to optimize without regard to roundoff or numerical exceptions. That is, the optimizer can assume the following:
o The IEEE 754 default rounding and trapping modes hold.
o No exceptions arise other than inexact.
o The program does not test for inexact exceptions.
o There are no infinities or NaNs.
o The program does not depend on distinguishing by the sign of zero.
−fsingle
(−Xt and −Xs modes only) Cause the compiler to evaluate float expressions as single precision, rather than double precision. (This option has no effect if the compiler is used in either −Xa or −Xc modes, as float expressions are already evaluated as single precision.)
−fstore
(x86 only) When a floating-point expression is assigned to a variable, this option forces the compiler to actually perform the assignment, instead of leaving the value in a floating-point register. This is the default.
−G Direct the link editor to produce a shared object rather than a dynamically linked executable. This option is passed to ld. It cannot be used with the −dn option.
−g Produces additional symbol table information for dbx(1) and debugger(1). This option no longer overrides −O and −xO .
−H Print, one per line, the path name of each file included during the current compilation on the standard error output.
−h name
Assign a name to a shared dynamic library; allows you to keep different versions of a library.
−Idir Look in dir, prior to the usual directories, for included files whose names do not begin with slash (/). Directories for multiple −I options are searched in the order specified.
−i Ignore the LD_LIBRARY_PATH setting.
−KPIC
Produce position-independent code. Each reference to a global datum is generated as a de-reference of a pointer in the global offset table. Each function call is generated in pc-relative addressing mode through a procedure linkage table.
−KPIC allows the global offset table to span the range of 32-bit addresses in those rare cases where there are too many global data objects for −Kpic.
−Kpic
Like −KPIC , except that the size of the global offset table is limited to 8K.
−keeptmp
Retain temporary files created during compilation, instead of deleting them automatically.
−Ldir Add dir to the list of directories searched for libraries by ld. This option and its argument are passed to ld.
−lname
Link with object library libname.so or libname.a (for ld(1)). This option must follow the sourcefile.
−mc This flag allows you to remove duplicate strings from the .comment section of an object file. When you use the -mc flag, -mcs -c is invoked.
−misalign
(SPARC only) -misalign assumes that data is not properly aligned and thus very conservative loads and stores must be used for data, that is, one byte at a time. Using this option can cause significant performance degradation when running the program.
−misalign2
(SPARC only) -misalign2, like -misalign, assumes that data is not properly aligned, but that data is at least half-word aligned. Though conservative uses of loads and stores must be used for data, the performance degradation when running a program should be less than for -misalign.
−mr This flag allows you to remove all strings from the .comment section of an object file. When you use the -mr flag, mcs -d is invoked.
−mr,string
This flag removes all strings from the .comment section and inserts string in the .comment section of the object file. If string contains embedded blanks, it must be enclosed in quotation marks. If string is null, the .comment section will be empty. When you use this flag, mcs -d -a is invoked.
−mt Passes D_REENTRANT to preprocessor. Also, appends −l thread. Use multi-thread safe libraries. If you are doing your own multi-thread coding, then you must use the −mt option in the compile and link steps. To get faster code, this option requires a multiprocessor system. On a single-processor system the generated code usually runs slower with this option.
−native
Best native floating point (SPARC only) or which processor (x86 only). Decide which floating-point options or which processor are available on the machine the compiler is running on, and generate code accordingly.
−nofstore
(x86 only) Do not force expressions to target precision on assignment.
−noqueue
Tells the compiler to not queue your request if no license if available.
−O Equivalent to −xO2 .
−o outputfile
Produce an output object file outputfile, instead of the default a.out. This option and its argument are passed to ld.
−P Preprocess only the named C files and leave the result in corresponding files suffixed .i. The output will not contain any preprocessing line directives, unlike −E.
−p Produce code that counts the number of times each routine is called; also, if link editing takes place, link profiled versions of libc.a and libm.a (with the −lm option). A mon.out file will then be produced at normal termination of execution of the object program. An execution profile can then be generated by use of prof.
−Q[y|n]
If y is used, identification information about each invoked compilation tool will be added to the output files (the default behavior). This can be useful for software administration. -Qn suppresses this information.
−q[l|p]
−ql (SPARC only) causes the invocation of the basic block analyzer and arranges for the production of code that counts the number of times each source line is executed. A listing of these counts can be generated by use of lprof. (Note that lprof will not be supported in future releases.)
−qp is a synonym for −p. −q cannot be used with the −O or −xO options.
−Rdir[:dir]
A colon-separated list of directories used to specify library search directories to the runtime linker. If present and not null, it is recorded in the output object file and passed to the runtime linker. If both LD_RUN_PATH and the -R option are specified, the -R option takes precedence.
Use this option if you want your users to be able to run your executables without a special path option to find your dynamic libraries.
−S Compile, optimize (if −O is present), and do not assemble or link edit the named C files. The assembler-language output is left in corresponding files suffixed .s.
−s Removes all symbolic debugging information from the output object file. This option is passed to ld(1).
−Uname
Cause any definition of name to be undefined, as if by a #undef preprocessing directive. If the same name is specified for both −D and −U, name is not defined, regardless of the order of the options.
−V Cause each invoked tool to print its version information on the standard error output.
−v Cause the compiler to perform more and stricter semantic checks, and to enable certain lint-like checks on the named C files.
−Wc,arg
Hand off the argument arg to c. Each argument must be separated from the preceding by only a comma. (A comma can be part of an argument by escaping it by an immediately preceding backslash (\) character; the backslash is removed from the resulting argument.) c can be one of the following:
a assembler (fbe)
c C code generator: (cg)(SPARC only), (codegen)(x86 only)
l link editor (ld)
m mcs
p preprocessor (cpp)
0 compiler (acomp and ssbd)
2 optimizer (iropt) (SPARC only), intermediate code translator (x86 only)
For example, −Wa,−o,objfile passes −o and objfile to the assembler, in that order; also −Wl,−I,name causes the linking phase to override the default name of the dynamic linker, /usr/lib/ld.so.1. manner.
The order in which the argument(s) are passed to a tool with respect to the other specified command line options may change.
−w Do not print warnings when compiling.
−X [a|c|s|t ]
Specify the degree of conformance to the ANSI C standard. Specify one of the following:
a (ANSI)
ANSI C plus Sun C compatibility extensions, with semantic changes required by ANSI C. Where Sun C and ANSI C specify different semantics for the same construct, the compiler will issue warnings about the conflict and use the ANSI C interpretation.
c (conformance)
Maximally conformant ANSI C, without Sun C compatibility extensions. The compiler will issue errors and warnings for programs that use non-ANSI C constructs.
s (Sun C)
The compiled language includes all features compatible with (pre-ANSI) Sun C. The compiler tries to warn about all language constructs that have differing behavior between Sun ANSI C and the old Sun C. Invokes cpp for processing. __STDC__ is not defined in this mode.
t (transition)
ANSI C plus Sun C compatibility extensions, without semantic changes required by ANSI C. Where Sun C and ANSI C specify different semantics for the same construct, the compiler will issue warnings about the conflict and use the Sun C interpretation. This is the default mode.
The predefined macro __STDC__ has the value 0 for −Xt and −Xa, and 1 for −Xc. (It is not defined for −Xs.) All warning messages about differing behavior can be eliminated through appropriate coding; for example, use of casts can eliminate the integral promotion change warnings.
−x386
(x86 only) Optimize for the 80386 processor.
−x486
(x86 only) Optimize for the 80486 processor.
−xa (SPARC only) Insert code to count how many times each basic block is executed. Invokes a runtime recording mechanism that creates a .d file for every .c file (at normal termination). The .d file accumulates execution data for the corresponding source file. The tcov(1) utility can then be run on the source file to generate statistics about the program. This option is incompatible with −g .
−xcg89
(SPARC only) Generate code to run on the SPARC architecture. This is the default option. Use a subset of the SPARC V8 instruction set. With -xcg89 and optimization, the instructions are scheduled for faster executables on a generic SPARC machine. Code compiled with -xcg89 does run on -xcg92 hardware.
−xcg92
(SPARC only) Generate code to run on SPARC V8 architecture. Allow the use of the full SPARC V8 instruction set. In particular, allow the following instructions to be generated in-line: smul, smulcc, sdiv, sdivcc, umul, umulcc, udiv, udivcc, and fsmuld. With -xcg92 and optimization, the instructions are scheduled for faster executables on a SuperSPARC machine. Code compiled with -xcg92 does run on older machines, but it may run slowly, as the new instructions added to SPARC V8 are emulated by traps to the operating system.
−xCC
Accepts the C++ style comments. In particular, the "//" can be used to indicate the start of a comment.
−xe Performs only error checking on the source file, but does not produce any object or executable file.
−xF Enables performance analysis of the executable using the Analyzer and Debugger. (See analyzer(1) and debugger(1) man pages.) Produces code that can be reordered at the function level. Each function in the file is placed in a separate section; for example, functions foo() and bar() will be placed in the sections .text%foo and .text%bar , respectively. Function ordering in the executable can be controlled by using −xF in conjunction with the −M option to ld (see ld(1)).
−xinline=[f1,...,fn]
For user-written routines, try to inline only those named in the list f1 to fn. It tries routines only in the file being compiled. The list is a comma-separated list of functions and subroutines.
If compiling with −xO3, this can increase optimization by inlining some routines. The −xO3 option inlines none by itself.
If compiling with −xO4, this can decrease optimization by restricting inlining to only those routines in the list. With −xO4, iropt normally tries to inline all user-written subroutines and functions. When xinline= is specified with an empty rlist, it indicates that none of the routines in the source file are to be inlined.
A routine is not inlined if any of the following apply (no warning):
o Optimization is less than -xO3
o The routine cannot be found
o Inlining the routine does not look profitable or safe to iropt
o The source for the routine is not in the file being compiled
−xlibmieee
Force IEEE 754 style return values for math routines in exceptional cases. In such cases, no exeception message will be printed, and errno will not be set.
−xlibmil
Include inline expansion templates for the math library (libm).
−xlicinfo
Does not check out a license but returns information on the status of licensing.
−xM Runs the ANSI preprocessor on the named C programs, generates makefile dependencies and sends the result to the standard output (see make(1) for details about makefiles and dependencies). Specifying −xM with −Xs runs the pre-ANSI preprocessor, /usr/ccs/lib/cpp .
−xM1
Same as −xM except that −xM1 does not report dependencies for /usr/include header files. For example:
more hello.c
#include <stdio.h>
main()
{
(void) printf ("hello0);
}
cc −xM hello.c
hello.o: hello.c
hello.o: /usr/include/stdio.h
Compiling with −xM1 does not report header file dependencies:
cc −xM1 hello.c
hello.o: hello.c
−xMerge
Directs cc to merge the data segment with the text segment. Data initialized in the object file produced by this compilation is read-only and (unless linked with ld-N) is shared between processes.
−xnolib
Does not link any libraries by default; that is, no −l options are passed to ld . Normally, the cc driver passes −lc to ld .
When you use −xnolib , you have to pass all −l options yourself. For example:
cc test.c −xnolib −Bstatic −lm −Bdynamic −lc
links libm statically and the other libraries dynamically.
−xnolibmil
Reset −fast so that it does not include inline templates. Use this after the −fast option:
cc –fast –xnolibmil ...
−xO [1,2,3,4]
Optimizes for execution time. May be used with −g. −O is equivalent to −xO2. (Note that the −ql will not be supported in future releases. Use −xa option. See tcov(1) for more information.) The four levels (1, 2, 3, or 4) differ according to the platform you are using.
( SPARC only)
1 Do only the minimum amount of optimization (peephole). This is postpass assembly-level optimization.
2 Do basic local and global optimization. This is induction variable elimination, local and global common subexpression elimination, algebraic simplification, copy propagation, constant propagation, loop-invariant optimization, register allocation, basic block merging, tail recursion elimination, dead code elimination, tail call elimination and complex expression expansion.
The −xO2 level does not assign global, external, or indirect references to registers. It treats these references and definitions as if they were declared "volatile." In general, the −xO2 level results in minimum code size.
3 Beside what −xO2 does, this also optimizes references and definitions for external variables. Loop unrolling and software pipelining are also performed. The −xO3 level does not trace the effects of pointer assignments. When compiling either device drivers, or programs that modify external variables from within signal handlers, you may need to use the volatile type qualifier to protect the object from optimization. In general, the −xO3 level results in increased code size.
4 Besides what −xO3 does, this also does automatic inlining of functions contained in the same file; this usually improves execution speed. The −xO4 level does trace the effects of pointer assignments. In general, the −xO4 level results in increased code size.
( x86 only)
1 Preloads arguments from memory, cross jumping (tail merging), as well as the single pass of the default optimization.
2 Schedules both high- and low-level instructions and performs improved spill analysis, loop memory-reference elimination, register lifetime analysis, enhanced register allocation, global common subexpression elimination.
3 Performs loop strength reduction, induction variable elimination, as well as the optimization done by level 2.
4 Performs loop unrolling, as well as the optimization done by levels 2 and 3.
If the optimizer runs out of memory, it tries to recover by retrying the current procedure at a lower level of optimization and resumes subsequent procedures at the original level specified in the command-line option.
If you optimize at −xO3 or −xO4 with very large procedures (thousands of lines of code in a single procedure), the optimizer may require an unreasonable amount of memory. In such cases, performance of the machine may degraded.
−xP Print function prototypes for all old-style functions in this compilation unit.
−xpentium
(x86 only) Optimize for the Pentium processor.
−xpg Prepare the object code to collect data for profiling with gprof(1). Invokes a runtime recording mechanism that produces a gmon.out file (at normal termination).
−xs Disable autoload for dbx. Use this option in case you cannot keep the .o files around. It passes the −s option to the assembler and the linker.
"No autoload" is the older way of loading symbol tables. The following process takes place: All symbol tables for dbx are placed in the executable file; the linker links more slowly and dbx initializes more slowly; if you move the executables to another directory, then to use dbx, you must move the source files, but you need not move the object (.o) files.
"Autoload" is the default way of loading symbol tables. The following process takes place: This information is distributed in the .o files, so that dbx loads the symbol table information only if and when it is needed; the linker links faster, and dbx initializes faster; if you move the executables to another directory, then to use dbx, you must move both the sources files and the object (.o) files.
−xsb Generate data in the .sb(5) directory for the sbrowser(1) program, part of the SourceBrowser.
−xsbfast
Generate data in the .sb(5) directory for the sbrowser(1) program, part of the SourceBrowser. Do not actually compile.
−xstrconst
Insert string literals into the text segment instead of the data segment.
−xtime
Reports the time spent compiling each component.
−xunroll=n
Specifies whether or not the compiler optimizes (unrolls) loops. n is a positive integer. When n is 1, it is a command and the compiler unrolls no loops. When n is greater than 1, the −xunroll=n merely suggests to the compiler that unrolled loops be unrolled n times.
−Yc,dir
Specify a new directory dir for the location of component c. c can consist of any of the characters representing tools listed under the −W option or the following characters representing directories containing special files:
I directory searched last for include files (see −I).
S directory containing the start-up object files.
P Change the default directories used for finding libraries. dir is a colon-separated path list.
If the location of a tool is being specified, then the new path name for the tool will be dir/tool. If more than one −Y option is applied to any one item, then the last occurrence holds.
−YA,dir
Specify a directory dir to search for all compiler components. If a component is not found in dir, the search reverts to the directory where the compiler is installed.
−YI,dir
Change default directory searched for include files.
−YP,dir
Change default directory for finding libraries files.
−YS,dir
Change default directory for startup object files.
−Zll (SPARC only) Create the lock_lint database files (.ll files), one per each .c file compiled for the lock_lint(1) program, which is included in the iMPact product. Do not actually compile.
−Ztha
(SPARC only) Prepare code for analysis by the thread analyzer, the performance analysis tool for multithreaded code.
cc recognizes -a, -e, -r, -t, -u, and -z and passes these options and their arguments to ld. cc also passes any unrecognized options to ld with a warning.
ENVIRONMENT
TMPDIR cc normally creates temporary files in the directory /tmp. You may specify another directory by setting the environment variable TMPDIR to your chosen directory. (If TMPDIR isn’t a valid directory, then cc will use /tmp).
SUNPRO_SB_INIT_FILE_NAME
The absolute path name of the directory containing the .sbinit(5) file. This variable is used only if the −xsb or −xsbfast flag is used.
FILES
a.out executable output file
file.a library of object files
file.c C source file
file.d tcov(1) test coverage input file
file.i C source file after preprocessing
file.il inline(1) expansion file
file.o object file
file.s assembler source file
file.tcov output from tcov(1)
acomp compiler front end
cc compiler command line driver
cg code generator
crt1.o runtime startup code
crti.o runtime startup code
crtn.o runtime startup code
fbe assembler
gcrt1.o startup for profiling with gprof(1)
gmon.out default profile file for -xpg
iropt global optimizer
mcrt1.o start-up for profiling with prof(1) and intro(3)
mon.out default profile file for -p
pcrt1.o start up for profiling with lprof
.sb The directory used to store sbrowser(1) data when the −xsb or −xsbfast flag is used.
.sbinit A file containing commands which can be used to specify the location of the .sb directory and to control the execution of sbcleanup
sbcleanup deletes obsolete files in the .sb directory and creates an up-to-date .sb/Index file
SEE ALSO
as(1), dbx(1), ld(1), lint(1), lprof(1), prof(1), monitor(3C), sbrowser(1), .sb(5), .sbinit(5), tmpnam(3S)
The C 3.0.1 User’s Guide. C 3.0.1 Transition Guide for SPARC Systems. Browsing Source Code. Kernighan, B. W., and Ritchie, D. M., The C Programming Language, Second Edition, Prentice-Hall, 1988. American National Standard for Information Systems − Programming Language C, X3.159-1989.
SunOS 3.0.1 — Last change: 30 June 1994