Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does "ar" utility do?

Tags:

c

unix

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....

like image 677
Karel Bílek Avatar asked Dec 06 '22 04:12

Karel Bílek


2 Answers

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.

like image 109
Brian Neal Avatar answered Jan 01 '23 13:01

Brian Neal


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.

like image 32
Paggas Avatar answered Jan 01 '23 14:01

Paggas