Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn thin archive into normal one

I'm building V8, and by default it builds as a "thin" archive, where the .a files essentially just contain pointers to the object files on your filesystem instead of containing the object files themselves. See man ar for details.

I want to be able to put this library in a central place so that other people can link to it, and it would be obviously much easier to provide a normal archive file instead of providing a gaggle of object files as well.

How do I take the thin archives produced by the build and turn them into normal ones? I assume it would be as simple as enumerating the object files in the thin archive and rebuilding an archive using those, but I don't know what command can be used to list the archive's object files.

like image 888
Matt Kline Avatar asked Aug 28 '14 17:08

Matt Kline


Video Answer


1 Answers

After some additional research, ar -t can be used to enumerate the object files in an archive, so after that it's just a matter of providing that list to ar as you usually would when creating an archive.

The following script handled this for all of the libraries at once:

for lib in `find -name '*.a'`;
    do ar -t $lib | xargs ar rvs $lib.new && mv -v $lib.new $lib;
done
like image 61
Matt Kline Avatar answered Nov 17 '22 06:11

Matt Kline