09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>XENIX</strong> Programming cc: C Compiler<br />

Using Object Files and Libraries<br />

The cc command can save useful functions as object files and use these object files to<br />

create programs at a later time. Because obj ect files contain the compiled or<br />

assembled instructions of your source file, they save you the time and trouble of<br />

recompiling the functions each time you need them. All object files created by cc have<br />

the file extension ".o".<br />

The cc command can also use functions found in <strong>XENIX</strong> system libraries, such as the<br />

standard C library or the screen processing library curses. To use these functions, you<br />

simply supply the name of the library containing them. However, cc accesses the<br />

standard C library automatically and no explicit naming is required.<br />

For convenience, you can create your own libraries with the ar and ranlib commands.<br />

These commands, described in Appendix B, "Programming Commands," copy your useful<br />

object files to a library file and prepare the file for use by the cc command. You can<br />

access the library like any other library in the system if you copy it to the /lib<br />

directory. You must name the library appropriately. The name must begin with a S, M,<br />

L, or H, identifying the model in which the library was compiled. Then, follow the<br />

capital letter with lib and the name you chose. Finally, supply the .a extension. For<br />

example, the small model curses library has the name Slibcurses.a.<br />

Creating Object Files<br />

You can create an object file from a given source file by using the -c (for "compile")<br />

option. This option directs cc to compile the source file without creating a final<br />

program. The option has the form<br />

-c filename ...<br />

where filename is the name of the source file. You may give more than one file name<br />

if you wish. Make sure each name is separated from the next by a space.<br />

To make object files for the source files add.c and mult.c, type<br />

cc -c add.c mult.c<br />

This command compiles each file and calls the compiled source files (object files)<br />

add.o and mult.o. It does not link these files; no executable program is created.<br />

The -c option is typically used to save useful functions for programs to be developed<br />

later. Once a function is in an object file it may be used as is, or saved in a library file<br />

and accessed like other library functions, as described in the following sections.<br />

Note that the cc command automatically creates an object file for each source file in<br />

the command line. Unless the -c option is given, however, it will also attempt to link<br />

these files, even if they do not form a complete program.<br />

2-7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!