To create object files, use the -c argument. The following example will give
the object file file.o:

	gcc -c file.c


gcc -o fred fred.c /usr/lib/libm.a
gcc -o fred fred.c -lm

The -lm (no space between the l and the m) is shorthand for the library
called libm.a in one of the standard library directories (in this case
/usr/lib). An additional advantage of the -lm notation is that the compiler
will automatically choose the shared library when it exists.

Static libraries, also known as archives, conventionally have names that end
with .a. Examples are /usr/lib/libc.a and /usr/X11/lib/libX11.a for the
standard C library and the X11 library.

Now let's create and use a library. We use the ar program to create the
archive and add our object files to it. The program is called ar because it
creates archives or collections of individual files placed together in one
large file. Note that we can also use ar to create archives of files of any
type (like many UNIX utilities, it is a very generic tool).

$ ar crv libfoo.a bill.o fred.o

The library is created and the two object files added. To use the library
successfully, some systems, notably those derived from Berkeley UNIX,
require that a table of contents be created for the library. We do this with
the ranlib command. This step isn't necessary (but harmless) when, as in
Linux, we're using the GNU software development tools.

$ ranlib libfoo.a

gcc -o program program.o libfoo.a
cc -o program program.o -L. -lfoo

The -L. option tells the compiler to look in the current directory for
libraries. The -lfoo option tells the compiler to use a library called
libfoo.a (or a shared library, libfoo.so if one is present).