libtool: Creating object files

1 
1 3.1 Creating object files
1 =========================
1 
1 To create an object file from a source file, the compiler is invoked
1 with the '-c' flag (and any other desired flags):
1 
1      burger$ gcc -g -O -c main.c
1      burger$
1 
1    The above compiler command produces an object file, usually named
1 'main.o', from the source file 'main.c'.
1 
1    For most library systems, creating object files that become part of a
1 static library is as simple as creating object files that are linked to
1 form an executable:
1 
1      burger$ gcc -g -O -c foo.c
1      burger$ gcc -g -O -c hello.c
1      burger$
1 
1    Shared libraries, however, may only be built from
1 "position-independent code" (PIC). So, special flags must be passed to
1 the compiler to tell it to generate PIC rather than the standard
1 position-dependent code.
1 
1    Since this is a library implementation detail, libtool hides the
1 complexity of PIC compiler flags and uses separate library object files
1 (the PIC one lives in the '.libs' subdirectory and the static one lives
1 in the current directory).  On systems without shared libraries, the PIC
1 library object files are not created, whereas on systems where all code
1 is PIC, such as AIX, the static ones are not created.
1 
1    To create library object files for 'foo.c' and 'hello.c', simply
1 Compile mode::):
1 
1      a23$ libtool --mode=compile gcc -g -O -c foo.c
1      gcc -g -O -c foo.c -o foo.o
1      a23$ libtool --mode=compile gcc -g -O -c hello.c
1      gcc -g -O -c hello.c -o hello.o
1      a23$
1 
1    Note that libtool silently creates an additional control file on each
1 'compile' invocation.  The '.lo' file is the libtool object, which
1 Libtool uses to determine what object file may be built into a shared
1 library.  On 'a23', only static libraries are supported so the library
1 objects look like this:
1 
1      # foo.lo - a libtool object file
1      # Generated by ltmain.sh (GNU libtool) 2.4.6
1      #
1      # Please DO NOT delete this file!
1      # It is necessary for linking the library.
1 
1      # Name of the PIC object.
1      pic_object=none
1 
1      # Name of the non-PIC object.
1      non_pic_object='foo.o'
1 
1    On shared library systems, libtool automatically generates an
1 additional PIC object by inserting the appropriate PIC generation flags
1 into the compilation command:
1 
1      burger$ libtool --mode=compile gcc -g -O -c foo.c
1      mkdir .libs
1      gcc -g -O -c foo.c  -fPIC -DPIC -o .libs/foo.o
1      gcc -g -O -c foo.c -o foo.o >/dev/null 2>&1
1      burger$
1 
1    Note that Libtool automatically created '.libs' directory upon its
1 first execution, where PIC library object files will be stored.
1 
1    Since 'burger' supports shared libraries, and requires PIC objects to
1 build them, Libtool has compiled a PIC object this time, and made a note
1 of it in the libtool object:
1 
1      # foo.lo - a libtool object file
1      # Generated by ltmain.sh (GNU libtool) 2.4.6
1      #
1      # Please DO NOT delete this file!
1      # It is necessary for linking the library.
1 
1      # Name of the PIC object.
1      pic_object='.libs/foo.o'
1 
1      # Name of the non-PIC object.
1      non_pic_object='foo.o'
1 
1    Notice that the second run of GCC has its output discarded.  This is
1 done so that compiler warnings aren't annoyingly duplicated.  If you
1 need to see both sets of warnings (you might have conditional code
1 inside '#ifdef PIC' for example), you can turn off suppression with the
1 '-no-suppress' option to libtool's compile mode:
1 
1      burger$ libtool --mode=compile gcc -no-suppress -g -O -c hello.c
1      gcc -g -O -c hello.c  -fPIC -DPIC -o .libs/hello.o
1      gcc -g -O -c hello.c -o hello.o
1      burger$
1