|
|
cc and CC command line options let you
Recall that the first line of our sample C program was
#include <stdio.h>The format of that directive is the one you should use to include any of the standard header files that are supplied with the C and C++ compilation systems. The angle brackets (< >) tell the preprocessor to search for the header file in the standard place for header files on your system. For C, this is usually the /usr/include directory. For C++ the standard place is usually /usr/include/CC, or, if the file is not found there, /usr/include. The format is different for header files that you have stored in your own directories:
#include "header.h"The quotation marks (``" "'') tell the preprocessor to search for header.h first in the directory of the file containing the #include line, which will usually be your current directory, then in the standard place.
If your header file is not in the current directory, specify the path of the directory in which it is stored with the -I option to cc or CC. For instance, if you have included both stdio.h and header.h in the source file test.c:
#include <stdio.h> #include "header.h"and header.h is stored in the directory ../defs, the command
$ cc -I../defs test.cwill direct the preprocessor to search for header.h first in the current directory, then in the directory ../defs, and finally in the standard place. It will also direct the preprocessor to search for stdio.h first in ../defs, then in the standard place. The only difference is that the current directory is searched only for header files whose name you have enclosed in quotation marks.
You can specify the -I option more than once on the cc or CC command line. The preprocessor will search the specified directories in the order they appear on the command line. You can therefore specify multiple options to cc or CC on the same command line:
$ cc -o prog -I../defs test.cThe C++ compiler provides a mechanism which may allow you to avoid recompiling a set of header files, producing an improvement in compilation time. See ``C++ precompiled headers'' for an explanation of this mechanism.
When you specify the -g option to cc or CC
$ cc -g test.cyou arrange for the compiler to generate information about program variables and statements that will be used by the debugger debug. The information supplied to debug will allow you to use it to trace function calls, display the values of variables, and set breakpoints. See ``Using the command line interface of debug'' and ``Using the graphical interface of debug'' for further information.
To use one of the profilers that are supplied with the C and C++ compilation systems, you must do two things:
prof: $ cc -qp test.c lprof: $ cc -ql test.c fprof: $ cc -qf test.c
$ a.out
prof: mon.out lprof: prog.cntwhere prog is the name of the profiled program. The files are inputs to the profilers. See ``Analyzing run-time behavior'' for further information.
The -O option to either cc or CC invokes the optimizer:
$ cc -O test.cThe optimizer improves the efficiency of the assembly language code generated by the compiler. That, in turn, will speed the execution time of your object code. Use the optimizer when you have finished debugging and profiling your program.
If you know the processor your code will normally be run on, you can specify that the compilation process should generate code that is optimized specifically for that processor. For more information, see the -K option on the cc(CP) and CC(C++) manual pages.
The -Qy option causes identification information about each invoked compilation tool to be added to the output file. This information can be useful for software administration. The information is placed in the .comment section of the resulting object file and can be printed by using the mcs command. For example:
mcs -p object_file | grep acompwill find the identification information associated with the compiler, acomp.