GNU Info

Info Node: (libtool.info)Creating object files

(libtool.info)Creating object files


Next: Linking libraries Up: Using libtool
Enter node , (file) or (file)node

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
(Note: Compile mode):

     a23$ libtool gcc -g -O -c foo.c
     gcc -g -O -c foo.c
     echo timestamp > foo.lo
     a23$ libtool gcc -g -O -c hello.c
     gcc -g -O -c hello.c
     echo timestamp > hello.lo
     a23$

   Note that libtool creates two files for each invocation.  The `.lo'
file is a library object, which may be built into a shared library, and
the `.o' file is a standard object file.  On `a23', the library objects
are just timestamps, 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 >/dev/null 2>&1
     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 >/dev/null 2>&1
     burger$

   Notice that the second run of GCC has its output discarded.  This is
done so that compiler warnings aren't annoyingly duplicated.


automatically generated by info2www version 1.2.2.9