Talk:Ar (Unix)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing / Software (Rated B-class, Low-importance)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
B-Class article B  This article has been rated as B-Class on the project's quality scale.
 Low  This article has been rated as Low-importance on the project's importance scale.
Taskforce icon
This article is supported by WikiProject Software (marked as Low-importance).
 

Ar vs tar[edit]

I've never entirely understood the differences in intent between ar and tar. I know that ar can create a symbol index for object files in the archive; and that tar has many more options for the structure of the file and the restoring of (e.g.) ownership and permissions. However, it's not clear to me, for instance, why the Debian package format (.deb files) prefers ar over tar, even though debs do not rely on a symbol index. --FOo 23:10, 10 Nov 2004 (UTC)

IIRC the ar format was chosen simply because it was sufficient and simpler to implement in dpkg :) --Joy [shallot] 10:42, 11 Nov 2004 (UTC)
Whilst you're a Debian developer and may know better, I was under the impression that ar was used because it was possible to get libmagic/file(1) to recognise .debs as Debian packages. In any case, dpkg handles tar.gz files. --Lucidion 14:14, 13 September 2006 (UTC)

Just a heads up...the file format as specified is currently incorrect/incomplete when referring to GNU ar. Dkmcnulty (talk) 03:16, 25 August 2009 (UTC)

Not sure how to mention this on the page without mangling since it's off-topic, but the fileformat for 'ar' is the exact same as for pecoff's archive (.lib) files. Creating an entry for the .lib format in Lib would largely result in a duplication of this Ar_(Unix) entry. -- 074fadd47e36c5627a2e7857a4ec480d920b96ea -- Anonymous (talk) 03:58, 29 December 2009 (UTC) —Preceding unsigned comment added by 66.68.167.173 (talk)

-L/-l being bad programming[edit]

The comment about being able to achieve linking results with -L. -lclass being bad programming seems to me to be subjective and/or oddly placed; I think that this comment should either be sourced or removed. Elehack (talk) 21:32, 4 March 2010 (UTC)

It is not only subjective but it is wrong. When using -L/-l the linker will only link the object files really needed. If the ar file contains unused object files these will not be linked. Using the file name of the ar file some linkers (I tried that with an old version of GNU ld for Windows) will link all object files into the executable even if they are not needed. Mr1278 (talk) 07:33, 19 July 2010 (UTC)

Example usage[edit]

I was curious so I played around with ar on my GNU/Linux system a little:

$ ar --version
GNU ar (GNU Binutils for Ubuntu) 2.21.0.20110327
Copyright 2011 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
$ echo 'This sentence is the contents of the first file.' > one.file
$ echo 'And this is inside the other file.' > two.file
$ ar -rc files.ar one.file two.file
$ cat files.ar 
!<arch>
one.file/       1337732246  1000  1000  100644  49        `
This sentence is the contents of the first file.

two.file/       1337732277  1000  1000  100644  35        `
And this is inside the other file.

$ hd files.ar
00000000  21 3c 61 72 63 68 3e 0a  6f 6e 65 2e 66 69 6c 65  |!<arch>.one.file|
00000010  2f 20 20 20 20 20 20 20  31 33 33 37 37 33 32 32  |/       13377322|
00000020  34 36 20 20 31 30 30 30  20 20 31 30 30 30 20 20  |46  1000  1000  |
00000030  31 30 30 36 34 34 20 20  34 39 20 20 20 20 20 20  |100644  49      |
00000040  20 20 60 0a 54 68 69 73  20 73 65 6e 74 65 6e 63  |  `.This sentenc|
00000050  65 20 69 73 20 74 68 65  20 63 6f 6e 74 65 6e 74  |e is the content|
00000060  73 20 6f 66 20 74 68 65  20 66 69 72 73 74 20 66  |s of the first f|
00000070  69 6c 65 2e 0a 0a 74 77  6f 2e 66 69 6c 65 2f 20  |ile...two.file/ |
00000080  20 20 20 20 20 20 31 33  33 37 37 33 32 32 37 37  |      1337732277|
00000090  20 20 31 30 30 30 20 20  31 30 30 30 20 20 31 30  |  1000  1000  10|
000000a0  30 36 34 34 20 20 33 35  20 20 20 20 20 20 20 20  |0644  35        |
000000b0  60 0a 41 6e 64 20 74 68  69 73 20 69 73 20 69 6e  |`.And this is in|
000000c0  73 69 64 65 20 74 68 65  20 6f 74 68 65 72 20 66  |side the other f|
000000d0  69 6c 65 2e 0a 0a                                 |ile...|
000000d6

- 193.84.186.81 (talk) 02:10, 23 May 2012 (UTC)