What exactly does "ar" utility do?
I don't really understand what ar
utility does on Unix systems.
I know it can be somehow used for 开发者_开发百科creating c libraries, but all that man page tells me is that it is used to make archives from files, which sounds similar to, for example, tar
....
The primary purpose is to take individual object files (*.o
) and bundle them together into a static library file (*.a
). The .a file contains an index that allows the linker to quickly locate symbols in the library.
Tar doesn't create files that linkers understand.
ar
is a general purpose archiver, just like tar
. It just "happens" to be used mostly for creating static library archives, one of its traditional uses, but you can still use it for general purpose archiving, though tar
would probably be a better choice. ar
is also used for Debian .deb
packages.
Exactly, ar is an archiver. It simply takes a set of object files (*.o) and put them in an archive that you call a static library.
It takes code in the form of object files (.obj, .o, etc) and makes a static library (archive). The library can then be included when linking with ld to include the object code into your executable.
Take a look at the example usage in the Wikipedia article.
You might want to run man ar
to get the full picture. Here's a copy of that on the web.
To quote:
The GNU ar program creates, modifies, and extracts from archives. An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files (called members of the archive).
ar
is considered a binary utility because archives of this sort are most often used as libraries holding commonly needed subroutines.
ar is specifically for archives (or libraries) of object code; tar is for archives of arbitrary files. Anybody's guess why GNU refers to these as 'archives', in other environments this utility is called the 'librarian', and the resulting files just libraries.
精彩评论