| A P P E N D I X B |
|
C Compiler Options Reference |
This chapter describes the C compiler options in alphabetical order. See Chapter 2 for options grouped by functionality. For example, TABLE 2-1 lists all the optimization and performance options.
Take note that the C compiler recognizes by default some of the constructs of the 1999 ISO/IEC C standard. Specifically, the supported features are detailed in Section , Supported Features of C99. Use the -xc99=none command if you want to limit the compiler to the 1990 ISO/IEC C standard.
If you are porting a K&R C program to ISO C, make special note of the section on compatibility flags, Section B.2.61, -X[c|a|t|s]. Using them makes the transition to ISO C easier. Also refer to the discussion on the transition in Chapter 6.
The syntax of the cc command is:
The C compiler accepts a list of C source files and object files contained in the list of files specified by filenames. The resulting executable code is placed in a.out, unless the -o option is used. In this case, the code is placed in the file named by the -o option.
Use the C compiler to compile and link any combination of the following:
After linking, the C compiler places the linked files, now in executable code, into a file named a.out, or into the file specified by the -o option. When the compiler produces object code for each .i or .c input file, it always creates an object (.o) file in the current working directory.
See option -YP, dir to change the default directories used for finding libraries. dir is a colon-separated path list. The default library search order for cc is:
cc uses getopt to parse command-line options. Options are treated as a single letter or a single letter followed by an argument. See getopt(3c).
This section describes the cc options, arranged alphabetically. These descriptions are also available in the man page, cc(1). Use the cc -flags option for a one-line summary of these descriptions.
Options noted as being unique to one or more platforms are accepted without error and ignored on all other platforms. For an explanation of the typographic notations used with the options and arguments, refer to Typographic Conventions.
Turns on verbose mode, showing how command options expand. Shows each component as it is invoked.
Shows each component as it would be invoked, but does not actually execute it. Also shows how command options would expand.
Associates name as a predicate with the specified tokens as if by a #assert preprocessing directive. Preassertions:
These preassertions are not valid 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.
Specifies whether bindings of libraries for linking are static or dynamic, indicating whether libraries are non-shared or shared, respectively.
-Bdynamic causes the link editor to look for files named libx.so and then for files named libx.a when given the -lx option.
-Bstatic 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(1).
This option and its argument are passed to the linker.
Prevents the C preprocessor from removing comments, except those on the preprocessing directive lines.
Directs the C compiler to suppress linking with ld(1) and to produce a .o file for each source file. You can explicitly name a single object file using the -o option. When the compiler produces object code for each .i or .c input file, it always creates an object (.o) file in the current working directory. If you suppress the linking step, you also suppress the removal of the object files.
Associates name with the specified tokens as if by a #define preprocessing directive. If no =tokens is specified, the token 1 is supplied.
Predefinitions (not valid in -Xc mode):
The following predefinitions are valid in all modes.
The following is predefined in -Xa and -Xt modes only:
The compiler also predefines the object-like macro __PRAGMA_REDEFINE_EXTNAME, to indicate the pragma will be recognized.
-dy specifies dynamic linking, which is the default, in the link editor.
-dn specifies static linking in the link editor.
This option and its arguments are passed to ld(1).
|
Note - This option causes fatal errors if you use it in combination with dynamic libraries. Most system libraries are only available as dynamic libraries. |
(SPARC) Obsolete. You should not use this option. Use -xmemalign=8s instead. See Section B.2.105, -xmemalign=ab for more information. For a complete list of obsolete options, see Section A.1.15, Obsolete Options.
Runs the source file through the preprocessor only and sends the output to stdout. The preprocessor is built directly into the compiler, except in -Xs mode, where /usr/ccs/lib/cpp is invoked. Includes the preprocessor line numbering information. See also the -P option.
Use this option if you want to prefix the string "error:" to the beginning of error messages so they are more easily distinguishable from warning messages. The prefix is also attached to warnings that are converted to errors by -errwarn.
If you do not specify this option, the compiler sets it to -errfmt=no%error. If you specify -errfmt, but do not supply a value, the compiler sets it to -errfmt=error.
This command suppresses C compiler warning messages and has no effect on error messages. This option applies to all warning messages whether or not they have been designated by -errwarn to cause a non-zero exit status.
t is a comma-separated list that consists of one or more of the following: tag, no%tag, %all, %none. Order is important; for example, %all,no%tag suppresses all warning messages except tag. The following table lists the -erroff values:
|
Suppresses the warning message specified by this tag. You can display the tag for a message by using the -errtags=yes option. |
|
The default is -erroff=%none. Specifying -erroff is equivalent to specifying -erroff=%all.
Only warning messages from the C compiler front-end that display a tag when the -errtags option is used can be suppressed with the -erroff option. You can achieve finer control over error message suppression. See Section 2.8.6, error_messages.
Use this option to control how much detail is in the error message produced by the compiler when it discovers a type mismatch. This option is particularly useful when the compiler discovers a type mismatch that involves a large aggregate.
i can be one of the following:
If you do not specify -errshort, the compiler sets the option to -errshort=full. If you specify -errshort, but do not provide a value, the compiler sets the option to -errshort=tags.
This option does not accumulate, it accepts the last value specified on the command line.
Displays the message tag for each warning message of the C compiler front-end that can be suppressed with the -erroff option or made a fatal error with the -errwarn option. Messages from the C compiler driver and other components of the C compilation system do not have error tags, and cannot be suppressed with -erroff and made fatal with -errwarn.
a can be either yes or no. The default is -errtags=no. Specifying -errtags is equivalent to specifying -errtags=yes.
Use the -errwarn option to cause the C compiler to exit with a failure status for the given warning messages.
t is a comma-separated list that consists of one or more of the following: tag, no%tag, %all, %none. Order is important; for example %all,no%tag causes cc to exit with a fatal status if any warning except tag is issued.
The warning messages generated by the C compiler change from release to release as the compiler error checking improves and features are added. Code that compiles using -errwarn=%all without error may not compile without error in the next release of the compiler.
Only warning messages from the C compiler front-end that display a tag when the -errtags option is used can be specified with the -errwarn option to cause the C compiler to exit with a failure status.
The following table details the -errwarn values:
The default is -errwarn=%none. If you specify -errwarn alone, it is equivalent to -errwarn=%all.
This option is a macro that can be effectively used as a starting point for tuning an executable for maximum runtime performance. -fast is a macro that can change from one release of the compiler to the next and expands to options that are target platform specific. Use the -# option or -xdryrun to examine the expansion of -fast, and incorporate the appropriate options of -fast into the ongoing process of tuning the executable.
The expansion of -fast now includes the new -xlibmopt option. This option enables the compiler to use a library of optimized math routines. For more information, see Section B.2.96, -xlibmopt.
The -fast option impacts the value of errno. See Section 2.10, The Value of errno for more information.
Modules that are compiled with -fast must also be linked with -fast. For a complete list of all compiler options that must be specified at both compile time and at link time, see Compile-Time and Link-Time Options.
The -fast option is unsuitable for programs intended to run on a different target than the compilation machine. In such cases, follow -fast with the appropriate -xtarget option. For example:
For C modules that depend on exception handling specified by SUID, follow -fast by -xnolibmil:
With -xlibmil, exceptions cannot be noted by setting errno or calling matherr(3m).
The -fast option is unsuitable for programs that require strict conformance to the IEEE 754 Standard.
The following table lists the set of options selected by -fast across platforms.
The optimizations performed by these options may alter the behavior of programs from that defined by the ISO C and IEEE standards. See the description of the specific option for details.
-fast acts like a macro expansion on the command line. Therefore, you can override the optimization level and code generation option aspects by following -fast with the desired optimization level or code generation option. Compiling with the -fast -xO4 pair is like compiling with the -xO2 -xO4 pair. The latter specification takes precedence.
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.
Reports K&R-style function definitions and declarations.
The compiler's treatment of extern inline functions conforms by default to the behavior specified by the ISO/IEC 9899:1999 C standard. Compile new codes with -features=no%extinl to obtain the same treatment of extern inline functions as provided by versions 5.5, or older, of the C and C++ compilers.
|
Generates extern inline functions as global functions. This is the default, which conforms with the 1999 C standard. |
|
Old C and C++ objects (created with Sun compilers prior to this release) can be linked with new C and C++ objects with no change of behavior for the old objects. To get standard conforming behavior, you must recompile old code with the current compiler.
If you do not specify a setting for -features, the compiler sets it to -features=extinl.
Prints a brief summary of each available compiler option.
(x86) Use this option to control how floating point expression are evaluated.
|
Floating point expressions are evaluated depending on the combination of the types of the variables and constants that make up an expression. |
If you do not specify -flteval, the compiler sets it to -flteval=any. If you do specify -flteval, but do not provide a value, the compiler sets it to -flteval=2.
You must not specify the following options in combination with -flteval=2:
See also Section D.1.1, Precision of Floating Point Evaluators.
(SPARC) This option is a macro for -fns and -ftrap=common.
The default is -fns=no, the SPARC standard floating-point mode. -fns is the same as -fns=yes.
Optional use of =yes or =no provides a way of toggling the -fns flag following some other macro flag that includes -fns, such as -fast.
On some SPARC systems, the nonstandard floating point mode disables "gradual underflow," causing tiny results to be flushed to zero rather than producing subnormal numbers. It also causes subnormal operands to be replaced silently by zero. On those SPARC systems that do not support gradual underflow and subnormal numbers in hardware, use of this option can significantly improve the performance of some programs.
When nonstandard mode is enabled, floating point arithmetic may produce results that do not conform to the requirements of the IEEE 754 standard. See the Numerical Computation Guide for more information.
This option is effective only on SPARC systems and only if used when compiling the main program. On x86 systems, the option is ignored.
This option causes subnormal results to be flushed to zero. Where available, this option also causes subnormal operands to be treated as zero.
This option has no effect on traditional x86 floating-point operations that do utilize the SSE or SSE2 instruction set.
(x86) -fprecision={single, double, extended}
Initializes the rounding-precision mode bits in the Floating-point Control Word to single (24 bits), double (53 bits), or extended (64 bits), respectively. The default floating-point rounding-precision mode is extended.
Note that on x86, only the precision, not exponent, range is affected by the setting of floating-point rounding precision mode.
Sets the IEEE 754 rounding mode that is established at runtime during the program initialization.
r must be one of: nearest, tozero, negative, positive.
The default is -fround=nearest.
The meanings are the same as those for the ieee_flags subroutine.
When r is tozero, negative, or positive, this flag sets the rounding direction mode to round-to-zero, round-to-negative-infinity, or round-to-positive-infinity respectively when a program begins execution. When r is nearest or the -fround flag is not used, the rounding direction mode is not altered from its initial value (round-to-nearest by default).
This option is effective only if used when compiling the main program.
Allows the optimizer to make simplifying assumptions concerning floating-point arithmetic.
The compiler defaults to -fsimple=0. Specifying -fsimple, is equivalent to -fsimple=1.
If n is present, it must be 0, 1, or 2.
Even with -fsimple=2, the optimizer is not permitted to introduce a floating point exception in a program that otherwise produces none.
See Techniques for Optimizing Applications: High Performance Computing written by Rajat Garg and Ilya Sharapov for a more detailed explanation of how optimization can impact precision.
(-Xt and -Xs modes only) Causes 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.
(x86) Causes the compiler to convert the value of a floating-point expression or function to the type on the left-hand side of an assignment, when that expression or function is assigned to a variable, or when the expression is cast to a shorter floating-point type, rather than leaving the value in a register. Due to rounding and truncation, the results may be different from those that are generated from the register value. This is the default mode.
To turn off this option, use the -nofstore option.
Sets the IEEE trapping mode in effect at startup but does not install a SIGFPE handler. You can use ieee_handler(3M) or fex_set_handling(3M) to simultaneously enable traps and install a SIGFPE handler. If you specify more than one value, the list is processed sequentially from left to right.
t can be one of the following values.
Note that the [no%] form of the option is used only to modify the meaning of the %all and common values, and must be used with one of these values, as shown in the example. The [no%] form of the option by itself does not explicitly cause a particular trap to be disabled.
If you do not specify -ftrap, the compiler assumes -ftrap=%none.
Example: -ftrap=%all,no%inexact means to set all traps except inexact.
If you compile one routine with -ftrap=t, compile all routines of the program with the same -ftrap=t option; otherwise, you might get unexpected results.
Use the -ftrap=inexact trap with caution. Use of -ftrap=inexact results in the trap being issued whenever a floating-point value cannot be represented exactly. For example, the following statement generates this condition:
This option is effective only if used when compiling the main program. Be cautious when using this option. If you wish to enable the IEEE traps, use -ftrap=common.
Produce a shared object rather than a dynamically linked executable. This option is passed to ld(1), and cannot be used with the -dn option.
When you use the -G option, the compiler does not pass any default -l options to ld. If you want the shared library to have a dependency on another shared library, you must pass the necessary -l option on the command line.
If you are creating a shared object by specifying -G along with other compiler options that must be specified at both compile time and link time, make sure that those same options are also specified when you link with the resulting shared object.
When you create a shared object, all the object files that are compiled with -xarch=v9 must also be compiled with an explicit -xcode value as documented in Section B.2.78, -xcode[=v].
Produces additional symbol table information for debugging with dbx(1) and the Performance Analyzer analyzer(1).
If you specify -g, and the optimization level is -xO3 or lower, the compiler provides best-effort symbolic information with almost full optimization. Tail-call optimization and back-end inlining are disabled.
If you specify -g and the optimization level is -xO4, the compiler provides best-effort symbolic information with full optimization.
Compile with the -g option to use the full capabilities of the Performance Analyzer. While some performance analysis features do not require -g, you must compile with -g to view annotated source, some function level information, and compiler commentary messages. See the analyzer(1) man page and the Performance Analyzer manual for more information.
The commentary messages that are generated with -g describe the optimizations and transformations that the compiler made while compiling your program. Use the er_src(1) command to display the messages, which are interleaved with the source code.
For more information on debugging, see the Debugging a Program With dbx manual.
Prints to standard error, one per line, the path name of each file included during the current compilation. The display is indented so as to show which files are included by other files.
Here, the program sample.c includes the files, stdio.h and math.h; math.h includes the file, floatingpoint.h, which itself includes functions that use sys/ieeefp.h:
% cc -H sample.c /usr/include/stdio.h /usr/include/math.h /usr/include/floatingpoint.h /usr/include/sys/ieeefp.h |
Assigns a name to a shared dynamic library as a way to have different versions of a library. In general, the name after -h should be the same as the file name given after the -o option. The space between -h and name is optional.
The linker assigns the specified name to the library and records the name in the library file as the intrinsic name of the library. If there is no -hname option, then no intrinsic name is recorded in the library file.
When the runtime linker loads the library into an executable file, it copies the intrinsic name from the library file into the executable, into a list of needed shared library files. Every executable has such a list. If there is no intrinsic name of a shared library, then the linker copies the path of the shared library file instead.
-I dir adds dir to the list of directories that are searched for #include files with relative file names prior to /usr/include, that is, those directory paths not beginning with a / (slash).
Directories for multiple -I options are searched in the order specified.
For more information on the search pattern of the compiler, see Section 2.14.1, Using the -I- Option to Change the Search Algorithm.
Passes the option to the linker to ignore any LD_LIBRARY_PATH or LD_LIBRARY_PATH_64 setting.
(SPARC) Obsolete. You should not use this option. Use -xcode=pic32 instead.
For more information, see Section B.2.78, -xcode[=v]. For a complete list of obsolete options, see Section A.1.15, Obsolete Options.
(x86) -KPIC is identical to -Kpic.
(SPARC) Obsolete. You should not use this option. Use -xcode=pic13 instead. For more information, see Section B.2.78, -xcode[=v]. For a complete list of obsolete options, see Section A.1.15, Obsolete Options.
(x86) Generate position-independent code for use in shared libraries (small model). Permits references to, at most, 2**11 unique external symbols.
Retains temporary files created during compilation instead of deleting them automatically.
Adds dir to the list of directories searched for libraries by ld(1). This option and its arguments are passed to ld(1).
|
Note - Never specify the compiler installation area, /usr/include, /lib, or /usr/lib, as search directories. |
Links with object library libname.so, or libname.a. The order of libraries in the command-line is important, as symbols are resolved from left to right.
This option must follow the sourcefile arguments.
Removes duplicate strings from the .comment section of the object file. When you use the -mc flag, mcs -c is invoked.
(SPARC) Obsolete. You should not use this option. Use the -xmemalign=1i option instead. For more information, see Section B.2.105, -xmemalign=ab. For a complete list of obsolete options, see Section A.1.15, Obsolete Options.
(SPARC) Obsolete. You should not use this option. Use the -xmemalign=2i option instead. For more information, see Section B.2.105, -xmemalign=ab. For a complete list of obsolete options, see Section A.1.15, Obsolete Options.
-mr removes all strings from the .comment section. When you use this flag, mcs -d -a is invoked.
-mr,string removes all strings from the .comment section and inserts string in that section of the object file. If string contains embedded blanks, it must be enclosed in quotation marks. A null string results in an empty .comment section. This option is passed as -d -astring to mcs.
Macro option that expands to -D_REENTRANT -lthread. If you are doing your own multithread coding, you must use this option in the compile and link steps. For a complete list of all compiler options that must be specified at both compile time and at link time, see TABLE 2-2. To obtain faster execution, this option requires a multiprocessor system. On a single-processor system, the resulting executable usually runs more slowly with this option.
This option is a synonym for -xtarget=native.
(x86) Does not convert the value of a floating-point expression or function to the type on the left-hand side of an assignment, when that expression or function is assigned to a variable or is cast to a shorter floating-point type; rather, it leaves the value in a register. See also Section B.2.27, -fstore.
Use default optimization level -xO3. The -O macro now expands to -xO3 instead of -xO2.
The change in default yields higher run-time performance. However, -x03 may be inappropriate for programs that rely on all variables being automatically considered volatile. Typical programs that might have this assumption are device drivers and older multi-threaded applications that implement their own synchronization primitives. The work around is to compile with -xO2 instead of -O.
Names the output file filename (as opposed to the default, a.out). filename cannot be the same as sourcefile, since cc does not overwrite the source file. This option and its arguments are passed to ld(1).
Runs the source file through the C preprocessor only. It then puts the output in a file with a .i suffix. Unlike -E, this option does not include preprocessor-type line number information in the output. See also the -E option.
Obsolete, see -xpg.
Emits or does not emit identification information to the output file. -Qy is the default.
If -Qy is used, identification information about each invoked compilation tool is added to the .comment section of output files, which is accessible with mcs. This option can be useful for software administration.
-Qn suppresses this information.
Passes 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.
Directs cc to produce an assembly source file but not to assemble the program.
Removes all symbolic debugging information from the output object file. This option cannot be specified with -g.
Undefines the preprocessor symbol name. This option removes any initial definition of the preprocessor symbol name created by -D on the same command line including those placed there by the command-line driver.
-U has no effect on any preprocessor directives in source files. You can give multiple -U options on the command line.
If the same name is specified for both -D and -U on the command line, name is undefined, regardless of the order the options appear. In the following example, -U undefines __sun:
Preprocessor statements of the following form in test.c will not take effect because __sun is undefined.
See Section B.2.7, -Dname[=tokens] for a list of predefined symbols.
Directs cc to print the name and version ID of each component as the compiler executes.
Directs the compiler to perform stricter semantic checks and to enable other lint-like checks. For example, the code:
compiles and executes without problem. With -v, it still compiles; however, the compiler displays this warning:
-v does not give all the warnings that lint(1) does. Try running the above example through lint.
Passes the argument arg to a specified component c. See TABLE 1-1 for a list of components.
Each argument must be separated from the preceding only by a comma. All -W arguments are passed after the regular command-line arguments. A comma can be part of an argument by using the escape character \ (backslash) immediately before the comma. All -W arguments are passed after the regular command-line arguments.
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.
The order in which the argument(s) are passed to a tool with respect to the other specified command line options may change.
c can be one of the following:
|
cc driver[1] |
|
Suppresses compiler warning messages.
This option overrides the error_messages pragma.
The -X (note uppercase X) options specify varying degrees of compliance to the ISO C standard. The value of -xc99 affects which version of the ISO C standard the -X option applies. The -xc99 option defaults to -xc99=all which supports the 1999 ISO/IEC C standard. -xc99=none supports the 1990 ISO/IEC C standard. See Appendix D for a discussion of supported 1999 ISO/IEC features. See Appendix H for a discussion of differences between ISO/IEC C and K&R C.
(c = conformance) Issues errors and warnings for programs that use non-ISO C constructs. This option is strictly conformant ISO C, without K&R C compatibility extensions. The predefined macro _ _STDC_ _ has a value of 1 with the -Xc option.
This is the default compiler mode. ISO C plus K&R C compatibility extensions, with semantic changes required by ISO C. Where K&R C and ISO C specify different semantics for the same construct, the compiler uses the ISO C interpretation. If the -Xa option is used in conjunction with the -xtransition option, the compiler issues warnings about the different semantics. The predefined macro _ _STDC_ _ has a value of 0 with the -Xa option.
(t = transition) This option uses ISO C plus K&R C compatibility extensions without semantic changes required by ISO C. Where K&R C and ISO C specify different semantics for the same construct, the compiler uses the K&R C interpretation. If you use the -Xt option in conjunction with the -xtransition option, the compiler issues warnings about the different semantics. The predefined macro _ _STDC_ _ has a value of 0 with the -Xt option.
(s = K&R C) Attempts to warn about all language constructs that have differing behavior between ISO C and K&R C. The compiler language includes all features compatible with K&R C. This option invokes cpp for preprocessing. _ _STDC_ _ is not defined in this mode.
(x86) Obsolete. You should not use this option. Use -xchip=generic instead. For a complete list of obsolete options, see Section A.1.15, Obsolete Options.
(x86) Obsolete. You should not use this option. Use -xchip=generic instead. For a complete list of obsolete options, see Section A.1.15, Obsolete Options.
Obsolete. Do not use this option. Use -xprofile=tcov instead. For a complete list of obsolete options and flags, see Section A.1.15, Obsolete Options.
The compiler uses the -xalias_level option to determine what assumptions it can make in order to perform optimizations using type-based alias-analysis. This option places the indicated alias level into effect for the translation units being compiled.
If you do not specify the -xalias_level command, the compiler assumes -xalias_level=any. If you specify -xalias_level without a value, the default is -xalias_level=layout.
The -xalias_level option requires optimization level -xO3 or above. If optimization is set lower, a warning is issued and the -xalias_level option is ignored.
Remember that if you issue the -xalias_level option but you fail to adhere to all of the assumptions and restrictions about aliasing described for any of the alias levels, the behavior of your program is undefined.
Replace l with one of the terms in the following table.
Specify instruction set architecture (ISA). If you use this option with optimization, the appropriate choice can provide good performance of the executable on the specified architecture. An inappropriate choice results in a binary program that is not executable on the intended target platform. Architectures that are accepted by -xarch are shown in TABLE B-12:
|
generic, generic64, native, native64, v8a, v8, v8plus, v8plusa, v8plusb, v9, v9a, v9b |
|
|
386, amd64, generic, generic64, native, pentium_pro, sse, sse2 |
Note that although -xarch can be used alone, it is part of the expansion of the -xtarget option and may be used to override the -xarch value that is set by a specific -xtarget option. For example:
overrides the -xarch=v8 set by -xtarget=ultra2.
The following table details the performance of an executable that is compiled with a given -xarch option and then executed by various SPARC processors. The purpose of this table is to help you identify the best -xarch option for your executable given a particular target machine. Start by identifying the range of machines that are of interest to you and then consider the cost of maintaining multiple binaries versus the benefit of extracting the last iota of performance from newer machines.
If you are compiling your executable with the v8plus or v8plusa instruction set, consider compiling with v9 or v9a instead. The v8plus and v8plusa options are provided so that programs can take advantage of some SPARC V9 and UltraSPARC features prior to the availability of Solaris 8 software with its support for 64-bit programs. Programs compiled with the