Static library including other static library

Mike Parker aldacron at gmail.com
Wed Feb 26 18:37:37 PST 2014


On 2/27/2014 6:28 AM, Andre wrote:
> Hi,
>
> I created a static library "webbrowser.lib" which depends on the dsource
> project WindowsAPI.
>
> I compile my static library by this statement:
> dmd main ... C:\D\WindowsAPI\dmd_win32_x32.lib -lib -of"webbrowser.lib"
>
> I get a static library with my webbrowser coding and it seems
> it als embedds the static library dmd_win32_x32.lib.
> (=> I think so due to the huge filesize 4.812 KB)

No, it doesn't "embed" any static libraries. If you actually compiled 
the WindowsAPI source together with yours, then the objects would end up 
in your library, but not just from importing them.

>
> While creating a bug report for Mono-D someone wrotes:
> "Static libraries cannot be linked into other static libraries, nor do
> dmd, gdc, or ldc support doing so".
>
> I am currently confused as it seems DMD can link static libraries
> into other static libraries.

That's not how static linking works. No link step happens when compiling 
a static library, so you can't "link static libraries into other static 
libraries."

>
> I also have a second project which is working with
> my static library webbrowser.lib.
>
> For me it seems a valid scenario to have a self contained static library
> webbrowser.lib.
>
> Do you know somethink about this?
>
>
If you want to create a single fat static lib then you can:

1) output only the object files for all the libraries you use, then 
combine them all into a single library by calling the lib tool 
(lib/ar/whatever).

2) extract the object files from the static libraries using the lib tool 
then use it again to combine them.

3) compile the source for each library you depend on into a single 
static lib.

I wouldn't recommend doing this, though, unless there's a very good 
reason. If you're worried about users having trouble compiling your 
dependencies, then just ship them with your library.


More information about the Digitalmars-d-learn mailing list