CC(1) — USER COMMANDS
NAME
CC − C++ compilation system
SYNOPSIS
CC [ -a ] [ -bsdmalloc ] [ −B dynamic ] [ −B static ] [ −c ] [ +d ] [ −dalign ] [ −dryrun ]
[ −Dname [=def ]] [ −E ] [+ e 0|+ e 1] [ −F [ [ −fast ] [ −fnonstd ] [ −g ] [ −g0 ]
[ −G ] [ −H ] [ −hname ] [ −help ] [ −Ipathname ] [+ i ] [ −J ] −keeptmp ] [ −llib ]
[ −Ldirectory ] [ −libmil ] [ −misalign ] [ −nolib ] [ −nolibmil ] [ −o outputfile ]
[ −O[ level ] [ −p ] [ −P ] [+ p ] [ −pg ] [ −pic ] [ −PIC ] [ −pipe ] [ −pta ] [ −ptn ]
[ −ptr pathname ] [ −pts ] [ −ptv ] [ −Qdir | −qdir directory ]
[ −Qoption | −qoption prog opt ] [ −Qpath | −qpath pathname ]
[ −Qproduce | −qproduce sourcetype ] [ −qp ] [ −ql ] [ −Rpath ] [ −S ] [ −sb ]
[ −sbfast ] [ −temp=directory ] [ −time ] [ −Uname ] [ −v ] [ −V ] [ −w ] [ + w ]
[ −xF ] [ −X m] [ −xs ] sourcefile ...
DESCRIPTION
CC (capital CC) uses the following components to compile C++ source code to object code.
acpp for preprocessing
cfront for syntax and type checking and translating to C code
acomp for translating to assembly code
as for translating to object code on SunOS 4.1.x
fbe for translating to object code on SunOS 5.0
iropt for optimizing, if the user specifies −O on the command line
ld for link editing
ptcomp for processing templates if the user program contains templates
ptlink for processing templates if the user program contains templates
For each C++ source file, file.c , CC creates a temporary file in the directory /tmp that contains the generated C file to be compiled with acomp . The +i option saves a copy of the generated C code (minus # line directives) in the current directory with the name file ..c
CC takes arguments ending in .c, .C, .cc, .cxx or .i to be C++ source programs. The .i files are presumed to be the output of acpp. Both .s and .o files are also accepted by the CC command. The .s files are treated as assembly source files that may be assembled and link edited, .o files are treated as object files that may be link edited.
Files whose names do not end with the above suffix are treated as object programs or libraries and are handed over to the link editor. Unless −c, −S, −E , −P , or −Qproduce is specified, these programs and libraries, together with the results of any specified compilations or assemblies, are linked (in the order given) to produce an output file named a.out. You can specify a name for the executable by using the −o option.
If a single file is compiled and linked all at once, the intermediate files are deleted (unless you specify +i or -keeptmp ).
Before you use the CC command, insert the name of the directory in which you have chosen to install the C++ compilation system at the beginning of your search path. This is generally /usr/lang/ for SunOS 4.1.x, or /opt/SUNWspro/bin/ for SunOS 5.0. This is usually done in the .cshrc file, in a line with set path = at the start; or in the .profile file, in a line with PATH= at the start.
Before you use the man command for CC man pages, insert /usr/lang/man for SunOS 4.1.x, or /opt/SUNWspro/man for SunOS 5.0 (or the name of the directory in which you have chosen to install the C++ translator) at the beginning of your man path. This is usually done in the .cshrc file, in a line with setenv MANPATH at the start; or in the .profile file, in a line with export MANPATH= at the start.
The CC driver links in several libraries by default by passing −l options to ld. On SunOS 5.0, the driver passes −lm -lC -lc to ld. On SunOS 4.1.x, the driver passes −lm -lansi -lC -lc to ld. This occasionally causes problems because the shared version of libC gets linked by default. Since the shared library libC.so is not bundled with the operating system, an application that has been linked dynamically with libC.so will not run on a machine that does not have a copy of libC.so. You may wish to link your applications statically with libC to circumvent this problem. To do this, use the −nolib option described below. If you use the −nolib option, the driver will not pass any −l options to ld, and you will have to pass these options yourself.
An example using −nolib with SunOS 4.1.x:
CC test.c -nolib -lm -lansi -Bstatic -lC -Bdynamic -lc
An example using −nolib with SunOS 5.0:
CC test.c -nolib -lm -Bstatic -lC -Bdynamic -lc
The above examples link statically with libC, libm and libansi. They link dynamically with libc. There are no shared versions of libm and libansi in this release of the compiler, but future releases may have shared versions of these two libraries as well. libansi is provided only on SunOS 4.1.x and is not needed on SunOS 5.0.
The order of specifying the −l options is important. The −lC, -lm, and −lansi options should appear before −lc. In addition, −nolib overrides any other option that would link in other libraries. For example, on SunOS 5.0, using the −ql option will cause the CC driver to pass −lprof -lelf to ld in addition to passing −lm -lC and −lc. If you use both −ql and −nolib, the CC driver will not pass any −l options to ld, including −lprof -lelf.
OPTIONS
All C++ compiler options are position independent.
CC interprets the following options:
−a Prepares object code for coverage analysis using tcov.
−bsdmalloc (SunOS 4.1.2 and 4.1.3 only) Faster malloc. Use the faster malloc from the library libbsdmalloc.a. This malloc is faster but less memory efficient. This option causes the flags -u_malloc and /lib/libbsdmalloc.a to be passed to the linker.
−B dynamic
Causes the link editor to first look for files named liblib.so and then, if not found, to look for files named liblib.a when given the −llib option. This is the default. This option may be specified multiple times on the command line as a toggle. The −B option and its argument are passed to ld.
−B static Causes the link editor to look only for files named liblib.a. The −B option may be specified multiple times on the command line as a toggle. The −B option and its argument are passed to ld.
−c Suppress linking with ld(1) and produce a .o file for each source file. A single object file can be named explicitly using the −o option.
−cg87 (SunOS 4.1.x.) For both the older and newer Sun-4 systems. This option directs the code generator to produce instruction scheduling and special instructions to exploit features available on Sun-4 systems released in 1987 or later. It also uses the appropriate in-line templates. It does not exploit features such as the fsqrts and fsqrtd instructions that are implemented in hardware on only the newer Sun-4 systems. The −cg87 option is the default.
−cg89 (SunOS 5.0 and 4.1.x.) Generates code for any newer SPARC system that has features like hardware fsqrts and fsqrtd instructions. Code compiled with -cg89 should not be executed on Sun-4/1xx and 4/2xx systems with Weitek 1164/5 floating-point hardware. Use the fpversion(1) command to tell you which floating-point hardware you have and which floating-point option to use. It may take about a minute to display its report.
−cg92 (SunOS 4.1.3 and SunOS 5.0 only.) For the newest SPARC computers. This directs the code generator to produce instruction scheduling and special instructions to exploit features available on SPARC systems released in 1992 or later. It also uses the appropriate in-line templates. Examples of such code are the integer multiply and divide instructions. Use the fpversion(1) command to tell you which floating-point hardware you have, and which floating-point option to use. It may take about a minute to display its report. Consistency: The −cg87, −cg89, and −cg92 options are mutually exclusive; you must use them consistently. This means that if you compile any procedure with one of these options, then you should compile all procedures of the program with same option. Similarly, for a library: compile all procedures in a library with the same −cg87, −cg89, or −cg92 option.
+d Do not expand inline functions.
−dalign Generates double load/store instructions whenever possible for improved performance. Assumes that all double typed data are double aligned, and should not be used when correct alignment is not assured.
−dryrun Shows but does not execute the commands constructed by the compilation driver.
−Dname[=def]
Defines a symbol name to the preprocessor acpp equivalent to a #define directive in the source. If no def is given, name is defined as ‘1’. This option is processed by acpp.
−E Runs only the preprocessor acpp on the C++ source files, and sends the result to the standard output.
+e[0|1] Use only on classes for which virtual functions are present, and all the virtual functions are either defined as inline or pure. In this circumstance, this option optimizes a program to use less space by ensuring that only one virtual table per class is generated. +e1 causes virtual tables to be external and defined. +e0 causes virtual tables to be external but only declared. This option is ignored for any class that contains an out-of-line virtual function. See Chapter 2 of the SPARCompiler C++ 3.0 Language System Release Notes for further information.
−F Runs only acpp and cfront on the C++ source files, and send the result to the standard output. The output contains #line directives.
−fast Selects the optimum combination of compilation options for speed. This should provide close to the maximum performance for most realistic applications. It is a convenience option, and it chooses the fastest code generation option available on the /fIcompile-time/fP hardware, the optimization level −02, a set of inline expansion templates, the −fnonstd floating-point option. 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 −02 , the optimization part of −fast-03 is −03 . 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.
−fnonstd Causes non-standard initialization of floating-point arithmetic hardware. By default, IEEE 754 floating-point arithmetic is nonstop and underflows are gradual. The −fnonstd option enables hardware traps to be enabled for floating-point overflow, 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).
−g Produces additional symbol table information for dbx(1) and debugger(1) and passes the −g option to acomp and the −lg flag to ld(1) (so as to include the g library, that is /usr/lib/libg.a ). This option impies +d , i.e. inline functions can also be debugged. With this option, cfront also produces C code for every declaration in the compilation rather than only for those declarations that are actually needed or used. This additional information allows for easier debugging, but it also increases the size of the object file because the symbol table is larger.
−g0 Same as -g, except that this option does not imply +d, i.e. inline functions cannot be debugged. This option will increase compilation speed as compared to the -g option, and will result in smaller object files.
−G (SunOS 5.0) Use to build a shared library (see ld(1)). All source files specified in the command line will be compiled with −pic. All object files specified in this command line should have been compiled with −pic.
−H Prints, one per line, the path name of each file included during the current compilation on the standard error output. This option is processed by acpp.
−hname Names a Shared Dynamic Library. (SunOS 5.0 only) The −h name option assigns a name to a shared dynamic library. This provides a way to have versions of a shared dynamic library. In general, the name after −h should be exactly what you have after the −o . You may optionally insert a space between −h and name.
−help Displays helpful information about CC.
−Ipathname Adds pathname to the list of directories in which to search for #include files with relative filenames (not beginning with slash /). The preprocessor first searches for #include files in the directory containing sourcefile, then in directories named with −I options (if any), and finally, in the places that the standard C++ header files reside. This option is processed by acpp.
+i Leaves the intermediate C files ending with the ..c suffix in the current directory during the compilation process. These files are the output of cfront and do not contain any preprocessing directives, although the files passed to acomp do.
−keeptmp Keeps all temporary files that are created during compilation. Useful for debugging especially when there are template functions or classes.
−llib Links with object library liblib.a or liblib.so (for ld(1)). This option must follow the sourcefile arguments.
−Ldirectory Adds directory to the search path for directories that contain object-library routines (for linking using ld(1)).
−libmil Selects the best inline templates for the floating-point option and operating system release available on this system.
−misalign Generates code to allow loading and storage of misaligned data.
−native Use appropriate code generator options.
−nolib Provides a way for linking libC statically and other libraries dynamically. You must specify the −l options yourself, together with the appropriate −Bstatic and −Bdynamic options. This option does not link any libraries by default, that is, no −l options are passed to ld; you must pass all −l options yourself. Normally, the CC driver passes -lm -lansi -lc to ld on a SunOS 4.1.x system. On a SunOS 5.0 system, the CC driver normally passes −lm -lC -lc to ld.
−nolibmil Resets −fast so that it does not include inline templates. Use this after the −fast option:
CC –fast –nolibmil ...
−o outputfile Names the output file outputfile. The outputfile must have the appropriate suffix for the type of file to be produced by the compilation (see FILES ). The outputfile cannot be the same as sourcefile (the compiler will not overwrite the source file).
−O[level] Optimizes for execution time. −O with the level omitted is equivalent to −O2. level is one of:
1 Do only the minimum amount of optimization (peephole). This is postpass assembly-level optimization. Do not use −O1 unless −O2 and −O3 result in excessive compilation time, or result in running out of swap space.
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 −O2 level does not optimize references or definitions for external or indirect variables. Do not use −O2 unless −O3 results in excessive compilation time, or running out of swap space. In general, the −O2 level results in minimum code size.
3 In addition to what −O2 does, this also optimizes references and definitions for external variables. The −O3 level does not trace the effects of pointer assignments. Do not use −O3 when compiling either device drivers, or programs that modify external variables from within signal handlers. In general, the −O3 level results in increased code size.
4 In addition to what −O3 does, this also does automatic inlining of functions contained in the same file; this usually improves execution speed, but occasionally makes it worse. In general, the −O4 level results in increased code size.
For most programs: −O4 is faster than −O3 is faster than −O2 is faster than −O1 . But in a few cases −O2 might beat the others, and −O3 might beat −O4 . You can try compiling with each level to see if you have one of these rare cases.
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 −O3 or −O4 with very large procedures (thousands of lines of code in a single procedure), the optimizer may require an unreasonably large amount of memory. In such cases, performance of the machine may be degraded. You can prevent this in the C-shell by limiting the amount of virtual memory available to a single process. To do this, use the limit command (see csh(1)).
−p Prepares the object code to collect data for profiling with prof(1). Invokes a run-time recording mechanism that produces a mon.out file (at normal termination).
−P Runs the source file through acpp, the C preprocessor, only. Puts the output in a file with a .i suffix. Does not include acpp-type line number information in the output.
+p Does not allow anachronistic constructs. Ordinarily the translator warns about anachronistic constructs; under +p (for “pure”), the translator will not compile code containing anachronistic constructs, such as “assignment to this.” See the SPARCompiler C++ 3.0.1 Language System Product Reference Manual for a list of anachronisms.
−pg Prepares the object code to collect data for profiling with gprof(1). Invokes a run-time recording mechanism that produces a gmon.out file (at normal termination).
−pic Produces position-independent code. Each reference to a global datum is generated as a dereference of a pointer in the global offset table. Each function call is generated in pc-relative addressing mode through a procedure linkage table. The size of the global offset table is limited to 8K on SPARC processors. For larger tables, see −PIC below.
−PIC Like −pic, but 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 −pic.
−pipe Uses pipes, rather than intermediate files, between acpp and cfront compilation stages. (Very cpu-intensive.)
The template instantiation system adds several options to CC . These are specified on the CC line or by setting the environment variable PTOPTS . For example, to permanently enable verbose mode, you would say:
export PTOPTS= -ptv
(in the .profile file)
setenv PTOPTS -ptv
(in the .cshrc file)
-pta Instantiates a whole template class rather than only those members that are needed.
-ptn Changes the default instantiation behavior for one-file programs to that of larger programs, where instantiation is broken out separately and the repository updated. One-file programs normally have instantiation optimized so that instantiation is done into the application object itself.
-ptrpathname
Specifies a repository, with ./ptrepository the default. If several repositories are given, only the first is writeable, and the default repository is ignored unless explicitly named.
-pts Split instantiations into separate object files, with one function per object (including overloaded functions), and all class static data and virtual functions grouped into a single object.
-ptv Turns on verbose or verify mode, which displays each phase of instantiation as it occurs, together with the elapsed time in seconds that phase took to complete. Use of this option is recommended if you are new to templates. With verbose mode, the reason why an instantiation is done and the exact CC command used are displayed.
Currently, -pts and -pta cannot be used together, that is, -pts can only be used to split up needed functions rather than all functions.
The preprocessor directives -I and -D work as they normally do, but must also be specified at link time, to pick up the various template and application type header files.
−Qdir | −qdir directory
Looks for compiler components in directory directory .
−Qoption | −qoption prog opt
Passes the option opt to the program prog. The option must be appropriate to that program and may begin with a minus sign. prog can be one of the following: acpp, acomp, cfront, fbe (on SunOS 5.0), as (on SunOS 4.1.x), iropt, ld, ptcomp, or ptlink.
−Qpath | −qpath pathname
Inserts directory pathname into the compilation search path. pathname will be searched first for versions of the compilation programs, such as acpp, and ld(1). This path will also be searched first for certain relocatable object files that are implicitly referenced by the compiler driver, for example ∗crt∗.o and bb_link.o.
−Qproduce | −qproduce sourcetype
Performs partial compilation and stops when a file of type sourcetype is generated. sourcetype can be one of:
.c C source (from cfront )
.i preprocessed C++ source from acpp
.o object file from fbe or as. fbe is used on SunOS 5.0, and as is used on SunOS 4.1.x
.s assembler source (from acomp)
−ql (SunOS 5.0). Prepares object code to collect data for profiling with lprof (1) .
−Rpath
(SunOS 5.0) A colon-separated list of directories used to specify library search directories to the run-time linker. If present and not null, it is recorded in the output object file and passed to the run-time linker. If both the LD_RUN_PATH and the -R option are specified, the -R option takes precedence.
−S Does not assemble the program but produces an assembly source file with a .s suffix.
−sb Generates extra symbol table information for the SourceBrowser.
−sbfast
Runs only acpp and cfront phases to generate the Source Browser database.
−temp=directory
(SunOS 4.x) Sets directory for temporary files to be directory.
−time
Reports execution times for the various compilation passes.
−Uname
Removes any initial definition of the acpp symbol name. (Inverse of the −D option.) This option is processed by acpp.
−v Verbose. Prints the name of each program it executes.
−V Prints the name and version ID of each pass of the compiler.
−w Do not print warnings.
+w Enables additional warning messages. Warns about constructs that are likely to be mistakes, to be non-portable, or to be inefficient. Without the +w option, the translator issues warnings only about constructs that are almost certainly errors.
−xF (SunOS 5.0) Enables performance analysis of the executable using the SPARCworks Analyzer and Debugger (see the analyzer (1) and debugger (1) manual 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)). This option will also cause fbe to generate some debugging information in the object file, necessary for data collection.
−Xm Allows the use of the character ’$’ in identifier names.
−xs (SunOS 5.0). Passes the −s option to the assembler. Use this only in cases where stabs must remain in the .stab section of the executable, and not in the default of .stab.excl. This older method of implementing symbol tables causes the loader to link more slowly and for dbx to initialize more slowly.
FILES
file.[Cc] input file
file.cc input file
file.cxx input file
file..c optional cfront output
file.o object file
a.out linked output
<path>/acpp the C++ preprocessor
<path>/cfront the C++ front end
/usr/lib/libc.a standard C library
<path>/libC.a standard C++ library
<path>/libtask.a C++ co-routine library
<path>/libcomplex.a C++ complex library
<path>/include/CC_411 standard directory for 4.1.1 #include files
<path>/include/CC_412 standard directory for 4.1.2 #include files
<path>/include/CC_413 standard directory for 4.1.3 #include files
<path>/include/CC standard directory for 5.0 #include files
Note:
The <path> statement shown above must be replaced by the
correct path at your installation site.
If you are using 4.x, the path will usually be /usr/lang/SC2.0.1
If you are using 5.0, the path will usually be /opt/SUNWspro/SC2.0.1
SEE ALSO
as(1), c++filt(1), cc(1), eprof(1), gprof(1), ld(1), monitor(3), prof(1), tcov(1).
Bjarne Stroustrup, The C++ Programming Language, Addison-Wesley 1991.
B. W. Kernighan and D. M. Ritchie, The C Programming Language, Prentice-Hall 1988.
SPARCompiler C++ 3.0 Language System Release Product Reference Manual.
SPARCompiler C++ 3.0 Programmer’s Guide, chapter 1 and chapter 4.
Sun Release 4.1 — Last change: 23 September 1992