Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A little used feature of the GNU archiver is the archive script, it is a simple but powerful interface, and it can do exactly what you want, for example if the following script is called script.ar:</p> <pre><code>CREATE libNewColor.a ADDLIB libColor.a ADDLIB libRGB.a ADDLIB libPixel.a SAVE END </code></pre> <p>Then you could invoke ar as follows:</p> <pre><code>ar -M &lt; script.ar </code></pre> <p>and you would get libNewColor.a that contains all of the .o files from libColor.a libRGB.a and libPixel.a.</p> <p>Additionally you can also add regular .o files as well with the ADDMOD command:</p> <pre><code>CREATE libNewColor.a ADDLIB libColor.a ADDLIB libRGB.a ADDLIB libPixel.a ADDMOD someRandomCompiledFile.o SAVE END </code></pre> <p>Furthermore it is super easy to generate these scripts in Makefiles, so I typically create a somewhat generic makefile rule for creating archives which actually generates the script and invokes ar on the script. Something like this:</p> <pre><code>$(OUTARC): $(OBJECTS) $(SILENT)echo "CREATE $@" &gt; $(ODIR)/$(ARSCRIPT) $(SILENT)for a in $(ARCHIVES); do (echo "ADDLIB $$a" &gt;&gt; $(ODIR)/$(ARSCRIPT)); done $(SILENT)echo "ADDMOD $(OBJECTS)" &gt;&gt; $(ODIR)/$(ARSCRIPT) $(SILENT)echo "SAVE" &gt;&gt; $(ODIR)/$(ARSCRIPT) $(SILENT)echo "END" &gt;&gt; $(ODIR)/$(ARSCRIPT) $(SILENT)$(AR) -M &lt; $(ODIR)/$(ARSCRIPT) </code></pre> <p>Though now that I look at it I guess it doesn't work if $(OBJECTS) is empty (i.e. if you just want to combine archives without adding extra object files) but I will leave it as an exercise for the reader to fix that issue if needed... :D</p> <p>Here are the docs for this feature:</p> <p><a href="https://sourceware.org/binutils/docs/binutils/ar-scripts.html#ar-scripts">https://sourceware.org/binutils/docs/binutils/ar-scripts.html#ar-scripts</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload