What does the "rcs" option in ar do?
Asked Answered
X

3

33

I did read the man file but it does not help. rcs seems to be the most popular option to pass to ar, but the meaning isn't so clear to me.

So c means to create a new archive, but then why use r? which seems to stand for "replace"? What will the s option do to the output?

Xanthochroism answered 18/4, 2015 at 7:24 Comment(1)
linuxcommand.org/man_pages/rcs1.htmlYoong
B
30

Reading the manual page (for ar) is a good start:

c

Create the archive. The specified archive is always created if it did not exist, when you request an update. But a warning is issued unless you specify in advance that you expect to create it, by using this modifier.

r

Insert the files member... into archive (with replacement). This operation differs from q in that any previously existing members are deleted if their names match those being added.

s

Write an object-file index into the archive, or update an existing one, even if no other change is made to the archive. You may use this modifier flag either with any operation, or alone. Running "ar s" on an archive is equivalent to running ranlib on it.

Comparing with POSIX, you may notice one difference: GNU ar makes the "-" prefixing options optional in itself.

An archive can contain other items than object-files (though this is not done often). Archives containing object-files require additional maintenance (e.g., done by ranlib) to make them usable by the linker.

According to the Rationale in POSIX ar, the -s option originated in BSD (System V did this automatically). However, running ranlib by itself is the prevailing practice (-s is rarely used). Interestingly enough, POSIX does not have ranlib, and ultimately the -s option will replace ranlib in the multitude of makefiles which were written to run on a variety of platforms.

Brande answered 18/4, 2015 at 11:38 Comment(0)
M
25

Reading the manual for ar helps but I will explain it in more detail. ar -rcs is the most likely command you would use when using a Makefile to compile a library. r means that if the library already exists, replace the old files within the library with your new files. c means create the library if it did not exist. s can be seen to mean 'sort' (create a sorted index of) the library, so that it will be indexed and faster to access the functions in the library. Therefore, rcs can be seen to mean replace, create, sort.

Menashem answered 2/7, 2018 at 2:25 Comment(0)
G
4

This means "Insert the files member... into archive (with replacement)."

Grammar answered 18/4, 2015 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.