On the usefulness of .la files and .pc files
Hi,
My question is slightly out of topic because it doesn't concern Buildroot specifically, but as it concerns the autotools build system, I thought I could share it with the list.
When compiling libraries using libtool, a .la file gets installed in /usr/lib. It defines several informations such as :
* The names of the library ;
* The dependencies of the library ;
* The directory where the library is installed ;
* A few other informations.
Many libraries also install a .pc file in /usr/lib/pkgconfig/. It also describe the dependencies, the library name, the flags to compile new applications/libraries on top of the library, etc.
I can't figure out why there are two different mechanisms. From my understanding, both of these files serve the same purpose : describe how new applications/libraries can be built against the library. Am I wrong ?
Let's take the example of libpng. It installs :
* /usr/lib/libpng12.la, with things like
dlname='libpng12.so.0' dependency_libs='-L/home/thomas/thirdparty/staging/usr/lib/ -lz -lm' libdir='/usr/lib'
* /usr/lib/pkgconfig/libpng12.pc, with :
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/libpng12
Name: libpng
Description: Loads and saves PNG files
Version: 1.2.35
Libs: -L${libdir} -lpng12
Libs.private: -lz -lm
Cflags: -I${includedir}
* /usr/bin/libpng12-config, which is a shell script that also basically gives the same information.
While I understand that /usr/bin/libpng12-config is a legacy script that predates the widespread usage of pkg-config, I can't figure out why both the .pc file and .la file are needed.
Any insight ?
Thanks a lot!
Thomas
Signature · 4 lines
Thomas Petazzoni, Free Electrons Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
Hi,
Quoted 7 lines · Thomas Petazzoni
When compiling libraries using libtool, a .la file gets installed in
/usr/lib. It defines several informations such as :* The names of the library ;
* The dependencies of the library ;
* The directory where the library is installed ;
* A few other informations.
This tells libtool how to link a particular library. This is mainly useful on platforms that need libraries to be explicitly linked. On Linux this is actually not needed and you may safely remove those files.
Quoted 3 lines
Many libraries also install a .pc file in
/usr/lib/pkgconfig/. It also describe the dependencies, the library name, the flags to compile new applications/libraries on top of the library, etc.
This gives hints on to compile stuff against the library. It is much more useful than the .la files as it allows to easily check for the presence of a library, it's version, dependencies and what compiler flags are needed.
Sven
Hi Sven,
Le Wed, 18 Mar 2009 18:24:45 +0100,
Sven Neumann <[email protected]> a ?crit :
Quoted 1 line
This tells libtool how to link a particular library.
What do you mean by ? link a particular library ? :
1) How to create the library itself (i.e, the .so file)
2) How to link an application or another library *against* the considered library ?
Quoted 2 lines
This is mainly useful on platforms that need libraries to be explicitly linked.
By ? explicitly linked ?, you mean that when compiling library A, that depends on B, which itself depends on C, you need to use -lB -lC, while on Linux, giving -lB is enough ?
Quoted 2 lines
On Linux this is actually not needed and you may safely remove those files.
So, why do we keep them and even patch them in Buildroot (see the $(BUILD_DIR)/%/.stamp_staging_installed: rule in package/Makefile.autotools.in). If the .la files are not patched (with the modification of the libdir variable), then the link step of other libraries or applications depending on the library fail. So the .la files are clearly used.
Quoted 8 lines
Quoted 3 lines
Many libraries also install a .pc file in
/usr/lib/pkgconfig/. It also describe the dependencies, the library name, the flags to compile new applications/libraries on top of the library, etc.This gives hints on to compile stuff against the library. It is much more useful than the .la files as it allows to easily check for the presence of a library, it's version, dependencies and what compiler flags are needed.
Ok. This is understood.
Thanks for your clarification!
Thomas
Signature · 4 lines
Thomas Petazzoni, Free Electrons Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com