What's the difference between:
ar -x liba.a
ar -x libb.a
ar rcs libab.a *.o
and
ar rcs libab.a liba.a libb.a
Are they really doing the same task?
What's the difference between:
ar -x liba.a
ar -x libb.a
ar rcs libab.a *.o
and
ar rcs libab.a liba.a libb.a
Are they really doing the same task?
Unless you're using a version of ar
that I don't know about, the effects of the two sequences of commands are quite different — though both end up creating a file libab.a
.
The first sequence extracts all the (object) files from liba.a
into the current directory, then all the files from libb.a
(any name collisions mean the file from libb.a
will survive), and then all the object files that are now in the directory (possibly including ones that were in neither liba.a
nor libb.a
) are archived in libab.a
.
The second sequence creates an archive that itself contains two files: liba.a
and libb.a
. This is legal and feasible, but the resulting file isn't useful in linking programs. The linker doesn't look at nested archives; it will simply find no object files that supply any symbols (since neither liba.a
nor libb.a
is an object file), so the library will effectively be unused — though you'll not get an error from attempting to use it.
It is more likely that the first sequence of commands is useful than the second.