summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--how_to_archive_with_posix_ar-1.pngbin0 -> 3480 bytes
-rw-r--r--how_to_archive_with_posix_ar.html106
-rw-r--r--index.html3
3 files changed, 109 insertions, 0 deletions
diff --git a/how_to_archive_with_posix_ar-1.png b/how_to_archive_with_posix_ar-1.png
new file mode 100644
index 0000000..135ed2f
--- /dev/null
+++ b/how_to_archive_with_posix_ar-1.png
Binary files differ
diff --git a/how_to_archive_with_posix_ar.html b/how_to_archive_with_posix_ar.html
new file mode 100644
index 0000000..b4dce3b
--- /dev/null
+++ b/how_to_archive_with_posix_ar.html
@@ -0,0 +1,106 @@
+<!doctype html>
+<html lang="en">
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<meta name="author" content="aki">
+<meta name="tags" content="tutorial, posix, ar, archive">
+<link rel="icon" type="image/png" href="cylo.png">
+<link rel="stylesheet" href="style.css">
+
+<title>How To Archive With POSIX ar</title>
+
+<nav><p><a href="https://ignore.pl">ignore.pl</a></p></nav>
+
+<article>
+<h1>How To Archive With POSIX ar</h1>
+<p class="subtitle">Published on 2021-07-26 00:47:00+02:00
+<p>Let's continue <a href="how_to_archive_with_posix_tar_cpio_and_pax.html">last POSIX archiving guide</a> 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.
+
+<p>It's time to stop pretending that <a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ar.html">ar</a>
+does not exists and learn how to use it.
+
+<p>Now then, when exactly do we want to use <b>ar</b>? Luckily, that's simple to answer. <b>ar</b> is used to create
+libraries of object files that are meant to be later linked against. In other words, it creates <i>static libraries</i>.
+In order to do it, <b>ar</b> maintains a symbol table. As long as at least one of the archived files is an object file,
+<b>ar</b> is obliged to do it completely automatically. However, usability of the archive for the linker is only
+guaranteed if all of the files are objects.
+
+<p>To create an empty archive:
+
+<pre>
+$ ar -r archive.a
+</pre>
+
+<p>Now, that's not very useful. Luckily for us, option <code>-r</code> actually means "replace or add" and accepts any
+number of paths after the archive name:
+
+<pre>
+$ ar -r archive.a file_a.o file_b.o ../../file_c.o
+</pre>
+
+<p>Assuming, that all of these files are present, they'll all be added to a new archive. If the <i>archive.a</i> already
+happens to exist, then files that are already occurring in it will get replaced. If not, then files will get appended.
+
+<p>To list contents of the symbol table, so the contents of the archive, use:
+
+<pre>
+$ ar -t archive.a
+file_a.o
+file_b.o
+file_c.o
+</pre>
+
+<p>Nice! Notice, that the <i>file_c.o</i> was added directly, without any additional path - just basename of the file.
+This will happen to every single file added to the archive. While adding files with same names you need to be cautious
+about it. Consider modifying our <i>archive.a</i> by:
+
+<pre>
+$ echo "Aloha!" > ../file_c.o
+$ ar -r archive.a ../file_c.o
+</pre>
+
+<p>This will overwrite our current <i>file_c.o</i> with one that says "Aloha!". This could be problematic, but it's
+generally easy to avoid and there are additional options that allow to do some shenanigans with the archive. Refer to
+your friendly manual or standard itself.</p>
+
+<img src="how_to_archive_with_posix_ar-1.png" alt="palm tree">
+
+<p>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 <code>-x</code> option:
+
+<pre>
+$ ar -x archive.a
+</pre>
+
+<p>This simply extract 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:
+
+<pre>
+$ ar -x archive.a file_c.o
+$ cat file_c.o
+Aloha!
+</pre>
+
+<p>The other way of extracting is closer to <b>cpio</b>. By using <code>-p</code> option content of selected files or
+the entire archive will be printed out to standard output:
+
+<pre>
+$ ar -p archive.a file_c.o
+Aloha!
+</pre>
+
+<p>Just note that if you specify multiple files to output, they will get concatenated.
+
+<p>And that's about it regarding basic <b>ar</b> usage. Quite a few sources will probably recommend that you always run
+<code>-s</code> option in every single operation you perform, in order to regenerate symbol table. However, that's not
+required at all, <b>ar</b> should be able to deal with it without any input from the user. The only case in which it is
+actually viable is after the archive was stripped. Otherwise, this suggestion is almost always useless.
+
+<p>If you are interested in precise management, then there are couple of options that will help i.a., <code>-d</code>
+for removal, <code>-u</code> for restricted updates, or <code>-p</code> for unchecked appending. But again, in normal
+usage, you probably won't need them as <code>-r</code> will deal with almost anything a <i>Makefile</i> will need.
+</article>
+<script src="https://stats.ignore.pl/track.js"></script>
diff --git a/index.html b/index.html
index 2612ae4..f7601f4 100644
--- a/index.html
+++ b/index.html
@@ -45,6 +45,7 @@ completely discard the concept of a keyboard.
<li>Miscellaneous Informative
<ul>
<li><a href="how_to_archive_with_posix_tar_cpio_and_pax.html">How To Archive With POSIX tar, cpio and pax</a>
+ <li><a href="how_to_archive_with_posix_ar.html">How To Archive With POSIX ar</a>
<li><a href="how_to_flash_lolin_nodemcu_v3.html">How To Flash LOLin NodeMCU v3</a>
<li><a href="journey_home_application_deployment.html">Journey /home - Application Deployment</a>
<li><a href="how_to_create_templates_with_shell_cat_and_envsubst.html">How To Create Templates With Shell, cat
@@ -68,6 +69,8 @@ completely discard the concept of a keyboard.
</nav>
<section id="news">
<h2>News</h2>
+<p><strong><time>2021-07-26</time></strong>
+Published <a href="how_to_archive_with_posix_ar.html">How To Archive With POSIX ar</a>.
<p><strong><time>2021-07-25</time></strong>
Renamed most of the guides to include "How To" in their name to make them more visible. I'm thinking about doing another
round of website restructurization.