>>> In VS2005, if APP A is using a static library B.lib, although there
>>> are many objects contained in the B.lib, but App only use part of it,
[quoted text clipped - 10 lines]
> The B.lib will include all the functions of C.lib, even there are no
> app use B.lib. Right?
Sealo:
No. A .lib file is not linked. It is just a collection of .obj files. If
your A.exe references B.lib, abd B.lib references C.lib, then all the
.obj files of B.lib and C.lib will be available to the A.exe linker.
Only those that are actually used will be retained in the image.

Signature
David Wilkinson
Visual C++ MVP
Ben Voigt [C++ MVP] - 26 Jun 2007 15:37 GMT
>>>> In VS2005, if APP A is using a static library B.lib, although there
>>>> are many objects contained in the B.lib, but App only use part of it,
[quoted text clipped - 14 lines]
>
> No. A .lib file is not linked. It is just a collection of .obj files. If
That's why it wouldn't contain only the functions of C needed by B. If you
pass C.lib to the lib command building B.lib, then C.lib will be included in
its entirety.
> your A.exe references B.lib, abd B.lib references C.lib, then all the .obj
> files of B.lib and C.lib will be available to the A.exe linker. Only those
> that are actually used will be retained in the image.
David Wilkinson - 26 Jun 2007 16:09 GMT
> "David Wilkinson" <no-reply@effisols.com> wrote in message
>> No. A .lib file is not linked. It is just a collection of .obj files. If
[quoted text clipped - 6 lines]
>> files of B.lib and C.lib will be available to the A.exe linker. Only those
>> that are actually used will be retained in the image.
Hi Ben:
Oh yes, I misread sealo's post. He didn't say that B.lib would contain
only the stuff from C.lib that it needed; somehow I thought he did.

Signature
David Wilkinson
Visual C++ MVP
Carl Daniel [VC++ MVP] - 26 Jun 2007 15:43 GMT
>>>> In VS2005, if APP A is using a static library B.lib, although there
>>>> are many objects contained in the B.lib, but App only use part of
[quoted text clipped - 18 lines]
> linker. Only those that are actually used will be retained in the
> image.
One more detail - the linker normally can only choose to load a module (an
.obj file) or not from a library - so if that module contains 20 functions
and only 1 is referenced, all 20 will still be present in the linked image.
But, there's a compiler switch - /Gy ("separate functions for linker") which
will put each and every function into it's own section, allowing the linker
to include only those functions that are actually used. Compiling with /Gy
will make your .obj's and .lib's larger and will increase link time, but
will normally decrease final image size.
-cd
David Wilkinson - 26 Jun 2007 16:15 GMT
> One more detail - the linker normally can only choose to load a module (an
> .obj file) or not from a library - so if that module contains 20 functions
[quoted text clipped - 4 lines]
> will make your .obj's and .lib's larger and will increase link time, but
> will normally decrease final image size.
Hi Carl:
I didn't know that. I thought that by default the linker would whittle
away at the image so that nothing not needed was present.
Another thing learned.

Signature
David Wilkinson
Visual C++ MVP
Ben Voigt [C++ MVP] - 26 Jun 2007 16:13 GMT
>> One more detail - the linker normally can only choose to load a module
>> (an .obj file) or not from a library - so if that module contains 20
[quoted text clipped - 10 lines]
> I didn't know that. I thought that by default the linker would whittle
> away at the image so that nothing not needed was present.
But the linker might not have the information on which global variables and
helper functions are used by which public functions...
> Another thing learned.
David Wilkinson - 26 Jun 2007 16:59 GMT
> "David Wilkinson" <no-reply@effisols.com> wrote in message
>> Hi Carl:
[quoted text clipped - 4 lines]
> But the linker might not have the information on which global variables and
> helper functions are used by which public functions...
Hi Ben:
Mmmm. The linker will sure complain if anything is missing, so why can't
it keep a list of things it has found not to be missing?
I dig myself a little deeper ...

Signature
David Wilkinson
Visual C++ MVP
Ben Voigt [C++ MVP] - 26 Jun 2007 17:28 GMT
>> "David Wilkinson" <no-reply@effisols.com> wrote in message
>>> Hi Carl:
[quoted text clipped - 9 lines]
> Mmmm. The linker will sure complain if anything is missing, so why can't
> it keep a list of things it has found not to be missing?
oops, I meant to say file-scoped variables and helper functions.... which
would be resolved by the compiler and not appear in the link symbols.
> I dig myself a little deeper ...