From bfa4c0d559c43d83d2d07014e7b765a287a0c944 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 26 Jul 2021 17:18:50 +0200 Subject: Fixed type and extended usage section of ar --- how_to_archive_with_posix_ar.html | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/how_to_archive_with_posix_ar.html b/how_to_archive_with_posix_ar.html index b4dce3b..77dd77c 100644 --- a/how_to_archive_with_posix_ar.html +++ b/how_to_archive_with_posix_ar.html @@ -13,14 +13,15 @@

How To Archive With POSIX ar

-

Published on 2021-07-26 00:47:00+02:00 +

Published on 2021-07-26 00:47:00+02:00, last modified on 2021-07-26 17:09:00+02:00

Let's continue last POSIX archiving guide from the very spot we finished. Today, we'll deal with just one tool. Very peculiar one, because it's more of a development utility than an archiver with portable format. In fact, it doesn't have a defined format at all. More than that, POSIX -acknowledges that several incompatible formats are known and that they don't care. +acknowledges that several incompatible formats are known and that they don't care. User can usually count on one +implementation to support archives created on another machine using the same implementation, so it's not that bad.

It's time to stop pretending that ar -does not exists and learn how to use it. +does not exist and learn how to use it.

Now then, when exactly do we want to use ar? Luckily, that's simple to answer. ar is used to create libraries of object files that are meant to be later linked against. In other words, it creates static libraries. @@ -69,13 +70,22 @@ your friendly manual or standard itself.

palm tree

You probably won't need to extract files from the archive, simply because you put it together so that the linker uses -it and not yourself. Still, you can extract files from it in two ways. First one is -x option: +it and not yourself, usually in a variation of one of the following ways. All depending on what tool is used as linker +and if the archive is available to it through its search paths: + +

+$ cc -l:archive.a main.o -o main
+$ ld main.o archive.a -o main
+
+ +

Still, if you need to extract files, you can extract them from library in two ways. First one uses -x +option:

 $ ar -x archive.a
 
-

This simply extract all of the files from the archive directly into current directory. Keep in mind that the paths +

This simply extracts all of the files from the archive directly into current directory. Keep in mind that the paths are not remembered, only the basenames are. Using those basenames you can also extract selected files from the archive:

-- 
cgit v1.1