174

What are libtool's .la files for? How are they used with a shared object?

1

3 Answers 3

161

It is a textual file that includes a description of the library.

It allows libtool to create platform-independent names.

For example, libfoo goes to:

Under Linux:

/lib/libfoo.so       # Symlink to shared object
/lib/libfoo.so.1     # Symlink to shared object
/lib/libfoo.so.1.0.1 # Shared object
/lib/libfoo.a        # Static library
/lib/libfoo.la       # 'libtool' library

Under Cygwin:

/lib/libfoo.dll.a    # Import library
/lib/libfoo.a        # Static library
/lib/libfoo.la       # libtool library
/bin/cygfoo_1.dll    # DLL

Under Windows MinGW:

/lib/libfoo.dll.a    # Import library
/lib/libfoo.a        # Static library
/lib/libfoo.la       # 'libtool' library
/bin/foo_1.dll       # DLL

So libfoo.la is the only file that is preserved between platforms by libtool allowing to understand what happens with:

  • Library dependencies
  • Actual file names
  • Library version and revision

Without depending on a specific platform implementation of libraries.

5
  • 7
    so how to you turn the .la file to a platform specific shared lib file, like libfoo.la -> libfoo.so.* Dec 31, 2009 at 15:39
  • 7
    You can't libfoo.la holds only meta information, i.e. in libfoo.la (textual file) written where should you find libfoo.so.x.y.z
    – Artyom
    Dec 31, 2009 at 20:48
  • 4
    Does it mean that in order to generate .la file, I need to use libtool (e.g. from automake)? One can rely on libtool to link the object files (gnu.org/software/libtool/manual/html_node/Using-Automake.html) but if I want to distribute a library without .la, does it mean it will be very difficult to link with it using Cygwin or mingw?
    – dma_k
    Jun 1, 2010 at 14:22
  • In case that anyone want to disable this version stuff, you can use -avoid-version in your _la_LDFLAGS, instead of -version-info
    – laishiekai
    Aug 8, 2018 at 23:13
  • 2
    @theactiveactor as .la file holds metadata, it must have static library somewhere. To find that, You can run libtool --mode-link ${whatever_command_you_would_use_for_linking} -lfoo -L${where_libfoo.la_exists} and it will print the linking command as debug info. In my case the static files were in .libs/ folder containing *.la file Nov 30, 2020 at 9:22
16

According to http://blog.flameeyes.eu/2008/04/14/what-about-those-la-files, they're needed to handle dependencies. But using pkg-config may be a better option:

In a perfect world, every static library needing dependencies would have its own .pc file for pkg-config, and every package trying to statically link to that library would be using pkg-config --static to get the libraries to link to.

14

I found very good explanation about .la files here http://openbooks.sourceforge.net/books/wga/dealing-with-libraries.html

Summary (The way I understood): Because libtool deals with static and dynamic libraries internally (through --diable-shared or --disable-static) it creates a wrapper on the library files it builds. They are treated as binary library files with in libtool supported environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.