While debugging a static linking problem this weekend, I needed to see which files were included in a static library. This can be accomplished with the ar(1) utilities “-t” (print table of contents) option:
$ ar -vt /usr/lib/libnsl.a | head 5
rw-rw-r-- 0/ 1 1752 Aug 13 10:16 2004 common.o
rw-rw-r-- 0/ 1 4868 Aug 13 10:16 2004 nsl_stdio_prv.o
rw-rw-r-- 0/ 1 3304 Aug 13 10:16 2004 des_crypt.o
rw-rw-r-- 0/ 1 25852 Aug 13 10:16 2004 des_soft.o
rw-rw-r-- 0/ 1 49088 Aug 13 10:17 2004 dial.o
If you need to extract a specific object file from a static library, you can invoke ar(1) with the “-x” option:
$ ar -vx /usr/lib/libnsl.a dial.o
$ ls -la dial.o
-rw-r–r– 1 root other 49088 Apr 25 16:17 dial.o
In case your interested, “-v” forces the archiver to produce verbose output. I am somewhat saddened that Solaris 10 will no longer support static libraries (though I understand why).