<p>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?</p>

[{'answer_id': 13136, 'author': 'Ed.', 'author_id': 522, 'author_profile': 'https://Stackoverflow.com/users/522', 'pm_score': 0, 'selected': False, 'text': "<p>I'm not sure how to physically combine them into a single file, however you could employ an abstraction of a sort and just include a single &quot;AllMyLibs.a/h&quot; which in turn includes everything you want.  You could also put this into the location where your compiler searches for libraries, so it would work for any project.</p>\n"}, {'answer_id': 13140, 'author': 'Avner', 'author_id': 1476, 'author_profile': 'https://Stackoverflow.com/users/1476', 'pm_score': 4, 'selected': True, 'text': '<p>On Unix like systems, the ld and ar utilities can do this. Check out <a href="http://en.wikipedia.org/wiki/Ar_(Unix)" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Ar_(Unix)</a> or lookup the man pages on any Linux box or through Google, e.g., \'Unix man ar\'.</p>\n<p>Please note that you might be better off linking to a shared (dynamic) library. This would add a dependency to your executable, but it will dramatically reduce its size, especially if you\'re writing a graphic application.</p>\n'}, {'answer_id': 13206, 'author': 'Judge Maygarden', 'author_id': 1491, 'author_profile': 'https://Stackoverflow.com/users/1491', 'pm_score': 5, 'selected': False, 'text': '<p>You could extract the object files from each library with</p>\n<pre class="lang-none prettyprint-override"><code>ar x &lt;library name&gt;\n</code></pre>\n<p>and then merge them all into a new library with</p>\n<pre class="lang-none prettyprint-override"><code>ar cs &lt;new library name&gt; &lt;list each extracted object file&gt;\n</code></pre>\n'}, {'answer_id': 22041, 'author': 'Greg Whitfield', 'author_id': 2102, 'author_profile': 'https://Stackoverflow.com/users/2102', 'pm_score': 0, 'selected': False, 'text': '<p>Maybe I\'m misunderstanding, but don\'t you only have to ship the libraries if the end-user code calls them directly? If all the access to JPEG methods, etc. is from your code in your static library, then just link the libraries into your library.</p>\n<p>I.e.,</p>\n<pre class="lang-none prettyprint-override"><code>---------------------\n| End-user EXE file |\n---------------------\n      |\n      | makes calls to\n      |\n      v\n --------------------\n | Your static lib.a |\n --------------------\n         | makes calls to and links\n         v\n     ------------------------------------ .....\n     |                    |         |\n  -------------    -------- ----------\n  | libjpeg.a |    |libz.a| |libpng.a|\n  -------------    -------- ----------\n</code></pre>\n<p>I.e., it\'s only an issue if the end code needs to make direct calls into libz.a, libpng.a, etc.</p>\n<p>If the application code has a legitimate need to call libz.a, for example, then that would as mentioned above be a case for using a dynamic module.</p>\n'}, {'answer_id': 31578, 'author': 'tuxedo', 'author_id': 3286, 'author_profile': 'https://Stackoverflow.com/users/3286', 'pm_score': -1, 'selected': False, 'text': "<p>Combining several third-party libraries into one could create more problems for you—for instance, if two of those libraries define a common symbol which your program doesn't use.  Now you've got to extract all (or all-but-one) of the instances of the common symbol before you combine the libraries.</p>\n"}, {'answer_id': 27676078, 'author': 'Star Brilliant', 'author_id': 2557927, 'author_profile': 'https://Stackoverflow.com/users/2557927', 'pm_score': 3, 'selected': False, 'text': '<p>On Linux, <a href="https://en.wikipedia.org/wiki/MinGW" rel="nofollow noreferrer">MinGW</a>, or <a href="https://en.wikipedia.org/wiki/Cygwin" rel="nofollow noreferrer">Cygwin</a>, with the GNU toolchain:</p>\n<pre class="lang-none prettyprint-override"><code>ar -M &lt;&lt;EOM\n    CREATE libab.a\n    ADDLIB liba.a\n    ADDLIB libb.a\n    SAVE\n    END\nEOM\nranlib libab.a\n</code></pre>\n<p>Or if you can keep the existence of <code>liba.a</code> and <code>libb.a</code>:</p>\n<pre class="lang-none prettyprint-override"><code>ar crsT libab.a liba.a libb.a\n</code></pre>\n<p>On Windows, with the <a href="https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B" rel="nofollow noreferrer">Microsoft Visual C++</a> toolchain:</p>\n<pre class="lang-none prettyprint-override"><code>lib.exe /OUT:libab.lib liba.lib libb.lib\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/13128', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1536/']