Libtool - Creating Object Files
Libtool - 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):
The above compiler command produces an object file, usually named 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:
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 and uses separate library object files (the PIC one lives in the .libs subdirectory
and the static one lives in the current directory). On systems without shared libraries, the
PIC library object files are not created, whereas on systems where all code is PIC, such as
AIX, the static ones are not created.
To create library object files for foo.c and hello.c, simply invoke libtool with the
standard compilation command as arguments (see Compile mode):
Note that libtool silently creates an additional control file on each ‘compile’ invocation.
The .lo file is the libtool object, which Libtool uses to determine what object file may be
built into a shared library. On ‘a23’, only static libraries are supported so the library
objects look like this:
https://www.gnu.org/software/libtool/manual/html_node/Creating-object-files.html 1/3
4/28/2021 Libtool: Creating object files
Note that Libtool automatically created .libs directory upon its first execution, where
PIC library object files will be stored.
Since ‘burger’ supports shared libraries, and requires PIC objects to build them, Libtool
has compiled a PIC object this time, and made a note of it in the libtool object:
Notice that the second run of GCC has its output discarded. This is done so that compiler
warnings aren’t annoyingly duplicated. If you need to see both sets of warnings (you
might have conditional code inside ‘#ifdef PIC’ for example), you can turn off
suppression with the -no-suppress option to libtool’s compile mode:
https://www.gnu.org/software/libtool/manual/html_node/Creating-object-files.html 2/3
4/28/2021 Libtool: Creating object files
https://www.gnu.org/software/libtool/manual/html_node/Creating-object-files.html 3/3