Ar
lastmod 2022-03-15created 2014-09-198 edits
(If you are looking for AR, the abbreviation for augmented reality, see the Augmented reality page.)
Archive, a command-line tool for static libraries.
Flags
-
d: Delete modules from the archive. If there are no files to delete, the archive is left untouched. -
t: Print the list of files in the archive. -
v: Verbose mode, which shows details. With this option, information such as file size and modification time is also printed. -
x: Extract object files from the archive. If thevoption is given, the names of the extracted files are printed. -
r: Add the object file if it is new, replace it if it already exists. -
c: Do not print a warning message even if the libhoge.a file does not exist. -
u: Compare object file timestamps and replace only if the file is newer. -
s: Create an archive index, like ranlib. Without an archive index, linking is slower, and depending on the system environment an error occurs. The archive index can be viewed with nm -s.
Example
-
ar cr [라이브러리 이름] [오브젝트 파일들]ar rcus [라이브러리 이름] [오브젝트 파일들] - Create an archive.
-
ar ds [라이브러리 이름] [오브젝트 파일들] - Remove objects from an existing archive file.
-
ar tv [라이브러리 이름] - View the contents of the archive.
-
ar xv [라이브러리 이름] - Extract files from the archive.
Merge archive
If you want to merge several static archive files, proceed as follows.
- Split out the Object files using
ar x {라이브러리}. - Merge all Object files using
ar cr {결과 라이브러리} *.o. - Create the index table using
ranlib {결과 라이브러리}.
Alternatively, you can use libtool.
Favorite site
- Hack #17: ar - Working with static libraries
- ar usage: creating archive files
- binutils: Structure of static libraries - ar, ranlib 1
- Static libraries and ar, ranlib, nm
References
-
Binutils-static_library-ar,ranlib.pdf ↩