Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2007

Tip: Looking for answers? Try searching our database.

The static library benefits

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sealo - 26 Jun 2007 03:25 GMT
Hello,
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,
will the compiler only adopted the part that the App actually need, or
bind all the objects of B.lib into the App?

App A --> B.lib
sealo - 26 Jun 2007 03:30 GMT
> Hello,
> In VS2005, if APP A is using a static library B.lib, although there
[quoted text clipped - 3 lines]
>
> App A --> B.lib

Later, I test it in the VS

App A --> B.lib --> C.lib

Then I call C.lib function in App A, it works.
It approve that, B.lib contain all the method of C.lib. But Whether
App A contain all the method of B and C.lib is unknown.
Mihai N. - 26 Jun 2007 08:30 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,
> will the compiler only adopted the part that the App actually need, or
> bind all the objects of B.lib into the App?

Only the used part is contained in the final application.
(it also depends how the lib is organized in modules).

Signature

Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

sealo - 26 Jun 2007 10:28 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 - 8 lines]
> ------------------------------------------
> Replace _year_ with _ to get the real email

The B.lib will include all the functions of C.lib, even there are no
app use B.lib. Right?
David Wilkinson - 26 Jun 2007 10:54 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 - 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 ...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.