What are libtool's .la file for?
Asked Answered
E

3

176

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

Exorbitance answered 6/8, 2009 at 10:11 Comment(1)
M
163

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.

Mateya answered 6/8, 2009 at 10:22 Comment(5)
so how to you turn the .la file to a platform specific shared lib file, like libfoo.la -> libfoo.so.*Hodgkin
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.zMateya
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?Bramante
In case that anyone want to disable this version stuff, you can use -avoid-version in your _la_LDFLAGS, instead of -version-infoCribb
@Hodgkin 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 fileCircumjacent
S
17

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.

Sleigh answered 9/2, 2012 at 19:8 Comment(0)
D
15

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.

Didst answered 22/8, 2012 at 22:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.