Next: Suffix Rules for Archive Files, Previous: Implicit Rule for Archive Member Targets, Up: Using make
to Update Archive Files [Contents][Index]
The built-in rules for updating archives are incompatible with parallel
builds. These rules (required by the POSIX standard) add each object file
into the archive as it’s compiled. When parallel builds are enabled this
allows multiple ar
commands to be updating the same archive
simultaneously, which is not supported.
If you want to use parallel builds with archives you can override the default rules by adding these lines to your makefile:
(%) : % ; %.a : ; $(AR) $(ARFLAGS) $@ $?
The first line changes the rule that updates an individual object in the
archive to do nothing, and the second line changes the default rule for
building an archive to update all the outdated objects ($?
) in one
command.
Of course you will still need to declare the prerequisites of your library using the archive syntax:
libfoo.a: libfoo.a(x.o y.o …)
If you prefer to write an explicit rule you can use:
libfoo.a: libfoo.a(x.o y.o …) $(AR) $(ARFLAGS) $@ $?