How to combine several C/C++ libraries into one?

GhassanPL picture GhassanPL · Aug 16, 2008 · Viewed 31.5k times · Source

I'm tired of adding ten link libraries into my project, or requiring eight of them to use my own. I'd like to take existing libraries like libpng.a, libz.a, libjpeg.a, and combine them into one single .a library. Is that possible? How about combining .lib libraries?

Answer

Judge Maygarden picture Judge Maygarden · Aug 16, 2008

You could extract the object files from each library with

ar x <library name>

and then merge them all into a new library with

ar cs <new library name> <list each extracted object file>