Intel XENIX 286 Programmers Guide (86) - Tenox.tc
Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc
XENIX Programming cc: C Compiler You can execute the new program by typing a.out The program waits until you enter two numbers, then prints their sum. For example, if you type "3 5" the program displays "8". Compiling Several Source Files Large source programs are often split into several files to make them easier to understand, update, and edit. You can compile such a program by giving the names of all the files belonging to the program when you invoke the cc command. The command reads and compiles each file in turn, then links all object files together, and copies the new program to the file a.out. To compile several source files, type cc filename • • • where each filename is separated from the next by at least one space. One of these files (and only one) must contain a "main" function. The others may contain functions called by this "main" function or by other functions in the program. The files must not contain calls to functions not explicitly defined by the program or by the standard C library. For example, suppose the following main program function is stored in the file main. #include extern int add(); main () { int x,y,z; } scanf ("%d %d", &x, &y); z = add (x, y); printf (" %d \n", z); Assume that the following function is stored in the file add.c. add (a, b) int a, b; { return (a + b); } You can compile these files and create an executable program by typing cc main.c add.c 2-3
cc: C Compiler XENIX Programming The command compiles the statements in main.c, then compiles the statements in add.c. Finally, it links the two together (along with the standard C library) and copies the program to a.out. This program, like the program in the previous section, waits for two numbers, then prints their sum. Since the cc command cannot keep track of more than one compiled file at a time, when several source files are compiled at a time, the command creates object files to hold the binary code generated for each source file. These object files are then linked to create an executable program. The object files have the same base name as the source files but are given the ".o" file extension. For example, when you compile the two source files above, the compiler produces the object files main.o and add.o. These files are permanent files, i.e., the command does not delete them after completing its operation. Note that the command also creates an object file if only one source file is compiled. Naming the Output File You can give the executable program file any valid file name by using the -o (for "output") option. The option has the form -o filename where filename is a valid file name or path name. If a file name is given, the program file is stored in the current directory. If a full path name is given, the file is stored in the given directory. If that file already exists, its contents are replaced with the new executable program. For example, the command cc -o addem main.c add.o causes the compiler to create an executable program file addem from the source file main.c and object file add.o. You can execute this program by typing add em Note that the -o option does not affect the existing a.out file. This means that the cc command does not change the current contents of a.out if the -o option has been given. Compiling Programs for the MS-DOS Environment The XENIX C compiler can compile programs that will operate in either the MS-DOS or the XENIX environment. However, to compile a program for the MS-DOS environment, you must use a different set of standard libraries and a different linker. The -dos option instructs the compiler to alter the standard search path and to search the appropriate libraries for the MS-DOS environment. Note that programs compiled with these libraries will not run in the XENIX environment. 2-4
- Page 1 and 2: 0 • • •
- Page 3 and 4: The information in this document is
- Page 5 and 6: Table of Contents CONTENTS Compiler
- Page 7 and 8: Table of Contents CONTENTS Using Ot
- Page 9 and 10: Table of Contents CONTENTS Assemble
- Page 11 and 12: Table of Contents CONTENTS CHAPTER
- Page 13 and 14: Table of Contents TABLES TABLE TITL
- Page 15 and 16: Introduction XENIX Programming 10.
- Page 17: cc: C Compiler XENIX Programming Cr
- Page 21 and 22: cc: C Compiler XENIX Programming Th
- Page 23 and 24: cc: C Compiler XENIX Programming Cr
- Page 25 and 26: cc: C Compiler XENIX Programming Th
- Page 27 and 28: cc: C Compiler XENIX Programming Co
- Page 29 and 30: cc: C Compiler XENIX Programming Sa
- Page 31 and 32: cc: C Compiler XENIX Programming Us
- Page 33 and 34: cc: C Compiler XENIX Programming Wh
- Page 35 and 36: cc: C Compiler XENIX Programming Co
- Page 37 and 38: cc: C Compiler XENIX Programming d
- Page 39 and 40: cc: C Compiler XENIX Programming Se
- Page 41 and 42: lint: C Program Checker XENIX Progr
- Page 43 and 44: lint: C Program Checker XENIX Progr
- Page 45 and 46: lint: C Program Checker XENIX Progr
- Page 47 and 48: lint: C Program Checker XENIX Progr
- Page 49 and 50: lint: C Program Checker XENIX Progr
- Page 51 and 52: lint: C Program Checker XENIX Progr
- Page 53 and 54: make: Program Maintainer XENIX Prog
- Page 55 and 56: make: Program Maintainer XENIX Prog
- Page 57 and 58: make: Program Maintainer XENIX Prog
- Page 59 and 60: make: Program Maintainer XENIX Prog
- Page 61 and 62: make: Program Maintainer XENIX Prog
- Page 63 and 64: make: Program Maintainer XENIX Prog
- Page 65 and 66: make: Program Maintainer print: $(F
- Page 67 and 68: SCCS: Source Code Control System XE
cc: C Compiler <strong>XENIX</strong> Programming<br />
The command compiles the statements in main.c, then compiles the statements in add.c.<br />
Finally, it links the two together (along with the standard C library) and copies the<br />
program to a.out. This program, like the program in the previous section, waits for two<br />
numbers, then prints their sum.<br />
Since the cc command cannot keep track of more than one compiled file at a time, when<br />
several source files are compiled at a time, the command creates object files to hold<br />
the binary code generated for each source file. These object files are then linked to<br />
create an executable program. The object files have the same base name as the source<br />
files but are given the ".o" file extension. For example, when you compile the two<br />
source files above, the compiler produces the object files main.o and add.o. These files<br />
are permanent files, i.e., the command does not delete them after completing its<br />
operation. Note that the command also creates an object file if only one source file is<br />
compiled.<br />
Naming the Output File<br />
You can give the executable program file any valid file name by using the -o (for<br />
"output") option. The option has the form<br />
-o filename<br />
where filename is a valid file name or path name. If a file name is given, the program<br />
file is stored in the current directory. If a full path name is given, the file is stored in<br />
the given directory. If that file already exists, its contents are replaced with the new<br />
executable program.<br />
For example, the command<br />
cc -o addem main.c add.o<br />
causes the compiler to create an executable program file addem from the source file<br />
main.c and object file add.o. You can execute this program by typing<br />
add em<br />
Note that the -o option does not affect the existing a.out file. This means that the cc<br />
command does not change the current contents of a.out if the -o option has been given.<br />
Compiling Programs for the MS-DOS Environment<br />
The <strong>XENIX</strong> C compiler can compile programs that will operate in either the MS-DOS or<br />
the <strong>XENIX</strong> environment. However, to compile a program for the MS-DOS environment,<br />
you must use a different set of standard libraries and a different linker.<br />
The -dos option instructs the compiler to alter the standard search path and to search<br />
the appropriate libraries for the MS-DOS environment. Note that programs compiled<br />
with these libraries will not run in the <strong>XENIX</strong> environment.<br />
2-4