Re: Replacing ar with libtool

Simon Richter <[email protected]> Sat, 10 Aug 2024 22:14:08 +0900
Newsgroups gmane.comp.gnu.libtool.general
Message-ID <[email protected]>
Hi,

On 8/10/24 20:08, Navin P wrote:

> When i run make -j1 i find all the object files  libx.a but when i 
> do make -j8 i find some missing object files inside libx.a.

Typically you'd generate all objects first, then archive them in a 
single invocation. This is I/O bound anyway, so you're not losing much 
from being single-threaded, and rerunning Make after a partial/failed 
build knows exactly which objects are missing.

Consider:

libx.a: a.o b.o
	$(AR) cru $@ $^

.c.o:
	$(CC) -o $@ -c $<

If you build a.o and add it to libx.a, then the next invocation of Make 
will compare the timestamp of libx.a against the timestamp of b.c, 
because b.o is an intermediate object, so the assumption is that it does 
not exist because it was successfully built and consumed by the only 
rule that references it.

This is safe only if the library is created last, i.e. will always have 
a timestamp that is later than any source files that go into it, so you 
cannot create an intermediate version of the library.

Libtool supports "convenience libraries", which are unpacked and 
repacked automatically to merge all objects to a single large library. 
That takes a bit of extra time in a build and cannot be parallelized 
either, but in large projects it makes the Makefile.am a little more 
readable.

    Simon
OpenPGP_signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEtjuqOJSXmNjSiX3Tfr04e7CZCBEFAma3Z6AACgkQfr04e7CZ
CBFfnggAsSdnssL8FCWKRxR0FFL42xTCjH8UBEPBwYYA5cl5zILwQKoHvv73oUjz
E9TWCOKUbHJ2tkdvwjocHknk4xnonaNLreL8lKeMVB71OlniuzJvJ02t8R6dbIFZ
ham22HAsbcnYSyEH3CARbJOwRI6f/D8B+yN1s2F5iJZOWSketNvmk8f0rFJU5JjG
Js4UseV5flb8qUExfZ72V1+7xZi+gFO2r+yPdgMdGLr2wzWzGPzhdl/6B23U6+uY
5NdJvNFdSWWvzMDRqUpKTCdMTmb7wmXXdDBOAGHL78q0aUfsXTCfTgF+2WGeG4JJ
/Mm/ZaU8ZW2K+1Ulf8ePUKp5EK2BrQ==
=fWGY
-----END PGP SIGNATURE-----