UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: cbChapter 2
Unix Commands
Next: Reference: cd
 

cc

/usr/ccs/bin/cc [options] files

Compile one or more C source files (file.c), assembler source files (file.s), or preprocessed C source files (file.i). cc automatically invokes the loader ld (unless -c is supplied). In some cases, cc generates an object file having a .o suffix and a corresponding root name. By default, output is placed in a.out. cc accepts additional system-specific options.

Notes

  • Add /usr/ccs/bin to your PATH to use the C compiler and other C Compilation System tools. This command runs the ANSI C compiler; use /usr/bin/cc if you want to run the compiler for pre-ANSI C.

  • Solaris 7 does not come with a C compiler. You must purchase one separately from Sun, or download the GNU C Compiler (GCC) from http://www.sunfreeware.com.

  • Options for cc vary wildly across Unix systems. We have chosen here to document only those options that are commonly available. You will need to check your local documentation for complete information.

  • Usually, cc passes any unrecognized options to the loader, ld.

Options

-c

Suppress loading and keep any object files that were produced.

-Dname[=def]

Supply a #define directive, defining name to be def or, if no def is given, the value 1.

-E

Run only the macro preprocessor, sending results to standard output.

-g

Generate more symbol-table information needed for debuggers.

-Idir

Search for include files in directory dir (in addition to standard locations). Supply a -I for each new dir to be searched.

-lname

Link source file with library files libname.so or libname.a.

-Ldir

Like -I, but search dir for library archives.

-o file

Send object output to file instead of to a.out.

-O

Optimize object code (produced from .c or .i files).

-p

Generate benchmark code to count the times each routine is called. File mon.out is created, so prof can be used later to produce an execution profile.

-P

Run only the preprocessor and place the result in file.i.

-S

Compile (and optimize, if -O is supplied), but don't assemble or load; assembler output is placed in file.s.

-Uname

Remove definition of name, as if through an #undef directive.

Example

Compile xpop.c and load it with the X libraries:

cc -o xpop xpop.c -lXaw -lXmu -lXt -lX11


Previous: Reference: cbUNIX in a Nutshell: System V EditionNext: Reference: cd
Reference: cbBook IndexReference: cd

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System