Embedding a library inside another static library

Is there a proper way to embed another library(static or dynamic) inside a static library?

Use-case:

We have two libraries A and B. "A" is a static library and "B" is a dependency which needs to be exposed only to A. Our goal is to provide a final packaged "A" static lib, with "B" embedded within it.

Look at man ar. You can extract your .a files, and then merge them back to a single .a file.

So this is possible for static libraries, but not possible for dynamic libraries, unless you have source files, so you can actually re-compile them as a single target.

1 Like