Go to the first, previous, next, last section, table of contents.


Creating object files

To create an object file from a source file, the compiler is invoked with the `-c' flag (and any other desired flags):

burger$ gcc -g -O -c main.c
burger$

The above compiler command produces an object file, `main.o', from the source file `main.c'.

For most library systems, creating object files that become part of a static library is as simple as creating object files that are linked to form an executable:

burger$ gcc -g -O -c foo.c
burger$ gcc -g -O -c hello.c
burger$

Shared libraries, however, may only be built from position-independent code (PIC). So, special flags must be passed to the compiler to tell it to generate PIC rather than the standard position-dependent code.

Since this is a library implementation detail, libtool hides the complexity of PIC compiler flags by using separate library object files (which end in `.lo' instead of `.o'). On systems without shared libraries (or without special PIC compiler flags), these library object files are identical to "standard" object files.

To create library object files for `foo.c' and `hello.c', simply invoke libtool with the standard compilation command as arguments:

a23$ libtool gcc -g -O -c foo.c
gcc -g -O -c foo.c
ln -s foo.o foo.lo
a23$ libtool gcc -g -O -c hello.c
gcc -g -O -c hello.c
ln -s hello.o hello.lo
a23$

Note that libtool creates two object files for each invocation. The `.lo' file is a library object, and the `.o' file is a standard object file. On `a23', these files are identical, because only static libraries are supported.

On shared library systems, libtool automatically inserts the PIC generation flags into the compilation command, so that the library object and the standard object differ:

burger$ libtool gcc -g -O -c foo.c
gcc -g -O -c -fPIC -DPIC foo.c
mv -f foo.o foo.lo
gcc -g -O -c foo.c
burger$ libtool gcc -g -O -c hello.c
gcc -g -O -c -fPIC -DPIC hello.c
mv -f hello.o hello.lo
gcc -g -O -c hello.c
burger$


Go to the first, previous, next, last section, table of contents.