From mccorkle@oasis1 Mon Mar 8 16:18:36 1993 Received: from oasis1.phy.bnl.gov by physgi01.phy.bnl.gov via SMTP (920330.SGI/911001.SGI) for nepsee id AA07261; Mon, 8 Mar 93 16:18:36 -0500 Received: by oasis1.phy.bnl.gov (920330.SGI/920502.SGI.AUTO) for nepsee@physgi01.phy.bnl.gov id AA07181; Mon, 8 Mar 93 16:22:00 -0500 Date: Mon, 8 Mar 93 16:22:00 -0500 From: mccorkle@oasis1 (Sean McCorkle) Message-Id: <9303082122.AA07181@oasis1.phy.bnl.gov> To: nepsee Subject: How to get started with C page Status: RO Essentials ---------- C programs are usually both compiled *and* linked with the cc command. Although unix does not have a file type or extension field, the compiler recognizes the suffix .c to indicate a C source file, and .o to indicate an object file. Executable (or binary) files generally do not have a suffix. A typical command to compile and link the main program prog.c and its associated subroutines may look like this: cc -o prog prog.c sub1.c sub2.o sub3.c The "-o prog" instructs the compiler to call the executable file "prog". If this is not specified, the name "a.out" will be used (this is an historical idiosyncracy). The compiler looks at the suffix of the subsequent arguments and will compile .c files, producing .o files (which are erased after linking) and linking them with any .o files specified. Often, it is desirable to only compile a .c file without linking. This is accomplished with the -c option: cc -c prog.c This produces the object file prog.o which may be linked at a later in this way: cc -c prog.o sub1.c sub2.o sub3.c Note that although the linking can be accomplished manually with the unix loader "ld", almost nobody does it this way, since cc does this for you. More Suffix Types ----------------- In addition to .c and .o, cc recognizes .s to be an assembly source file, .a to be a library archive, .f to be a fortran program (in which case f77 .s invoked to produce a .o file), .i to be C source file produced by running the C preprocessor on it. CC can also produce ucode object files, with the extension .u if you specify the -j option. Using Libraries --------------- In addition to linking with user created archive libraries (.a files) a user may also link with one of the many system libraries with the -l option. By specifing -labc on the cc command, the compiler will link with the system library libabc.a; this will be searched for in the directories /lib, /usr/lib and /usr/local/lib. You can have additional directories searched by specifing -L "dir" before any -l options. Important libraries which are not searched by default include -lm (the math library: cos(), exp(), tan(), etc) and -LX11 (the X11 library). Other Useful Options -------------------- #include files are searched for in the source file's directory first, and then in the standard directory /usr/include. You can suppress this by specifying -I or you can add additional directories to be seached by specifying -Idir. The -P option runs only the preprocessor on each source file and puts the output in .i files. This is useful if you have problems with macros. For Additional Information -------------------------- man cc - C compiler documentation man ld - loader (linker) documentation man "func" - documentation on library function "func" ( i.e, man cos or man exp )