469,314 Members | 2,203 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

How is a "static library" different from a "DLL"

jr
I am working in VC++ so this may be microsoft specific though I don't think
so. Excuse me if it is.

Assuming it isn't, can someone generally explain the purpose of having
both - is it purely a deployment/distribution thing.

I notice that the static library generates obj files and a Lib file. Could
someone kindly explain how they relate to one another.

Thanks very much

John

--
---
If you need to reply personally, append "text" to the domain name in my
email adr.
Thanks
Jul 22 '05 #1
4 1974

"jr" <jo***@tele.co.uk> wrote in message
news:c7**********@newsg3.svr.pol.co.uk...
I am working in VC++ so this may be microsoft specific though I don't think so. Excuse me if it is.

Assuming it isn't, can someone generally explain the purpose of having
both - is it purely a deployment/distribution thing.

I notice that the static library generates obj files and a Lib file. Could
someone kindly explain how they relate to one another.

Thanks very much

John

--
---
If you need to reply personally, append "text" to the domain name in my
email adr.
Thanks


An obj file is generated when a C++ source file (et. al.) is compiled. It
is linked with other (or possibly none) obj files to form an executable. A
lib file is an archive (equilivant to a unix *.a file). It contains 1 or
more objs. Your linker will search a lib file for undefined symbols. If it
finds any symbols that it needs in the archive, it will link in the
object(s) that contain them. A DLL is a dynamically linked library (similar
to a unix shared library or *.so file). It is loaded during runtime by
programs that need it and is shared by other running programs that also need
it.

Simplicistic, but good enough I guess.
Jul 22 '05 #2
jr
Thanks
Great help.

"Xenos" <do**********@spamhate.com> wrote in message
news:c7*********@cui1.lmms.lmco.com...

"jr" <jo***@tele.co.uk> wrote in message
news:c7**********@newsg3.svr.pol.co.uk...
I am working in VC++ so this may be microsoft specific though I don't think
so. Excuse me if it is.

Assuming it isn't, can someone generally explain the purpose of having
both - is it purely a deployment/distribution thing.

I notice that the static library generates obj files and a Lib file. Could someone kindly explain how they relate to one another.

Thanks very much

John

--
---
If you need to reply personally, append "text" to the domain name in my
email adr.
Thanks


An obj file is generated when a C++ source file (et. al.) is compiled. It
is linked with other (or possibly none) obj files to form an executable.

A lib file is an archive (equilivant to a unix *.a file). It contains 1 or
more objs. Your linker will search a lib file for undefined symbols. If it finds any symbols that it needs in the archive, it will link in the
object(s) that contain them. A DLL is a dynamically linked library (similar to a unix shared library or *.so file). It is loaded during runtime by
programs that need it and is shared by other running programs that also need it.

Simplicistic, but good enough I guess.

Jul 22 '05 #3
John,

DLL = dynamic link library. This means that the library code is not
actually
linked into your executable, but remains in a separate file and is loaded
either
when you start the executable, or can actually be loaded on-request by the
program.

DLLs are somewhere between the .lib file and the executable on the
evolutionary path,
DLLs are actually linked , .lib files are merely repositories for .obj files
and other .libs, just
packaged into a more convenient medium. Symbols in DLLs have to be
partially resolved,
that is to say if you call foo() it better be in the DLL or in another DLL
which the first
DLL refers to.

..lib files are linked into the executable code. The code in the .lib file
"becomes" part of
the executable. They are really just collections of .obj's

When you create a DLL, a .lib is also created. This is actually a "proxy"
which I will explain.

The DLL's .lib file will contain stubs or dummies for each of the functions
you export from the dll.
The .lib is linked into your executable as a place holder to call functions
in the DLL.
When you make a call to a function foobar(), the .lib stub foobar() will
actually execute the
function in the dll for you. This is all taken care of under the hood for
you when you use DLLs.
The advantages of DLLs are:

1. you can update the DLL without relinking the executable or
redistribution the executable.
( provided you don't add new functions or changes interfaces )
2. One DLL can be shared amongst a number of different executables so you
save on disk storage.
In reality, there are normally several copies of a DLL because
executables often require an
exact version of a dll to work correctly.
3. Since DLLs can be loaded on-demand, the start up time of the exectuable,
its memory footprint, etc
can be minimized to the essential functionality. Many of microsoft's
products make heavy use of
this feature through another technology called COM, which provides a
streamlined means to
execute functions in a dynamically loaded DLL.

Disadvantages:
1. DLL HELL - you have multiple versions of DLL which are all incompatible
with each other.
2. DLL code may be slightly slower in execution speed because of the code
has be to
relocatable at run-time and certain optimizations cannot be performed.
3. You have to ship DLLS along with the executable, so its a bit more
complex in deployment.
You also have to be sure your executable is picking up the correct
versions of DLLs on the
system.
4. There are some arcane rules for exporting functions from a DLL, just
adding the code is
not enough. However, these rules are fairly mechanical, and can be
mastered after a few
encounters.

Hope that helps.

dave

"jr" <jo***@tele.co.uk> wrote in message
news:c7**********@newsg3.svr.pol.co.uk...
I am working in VC++ so this may be microsoft specific though I don't think so. Excuse me if it is.

Assuming it isn't, can someone generally explain the purpose of having
both - is it purely a deployment/distribution thing.

I notice that the static library generates obj files and a Lib file. Could
someone kindly explain how they relate to one another.

Thanks very much

John

--
---
If you need to reply personally, append "text" to the domain name in my
email adr.
Thanks

Jul 22 '05 #4
"Dave Townsend" <da********@comcast.net> wrote in message
news:gO********************@comcast.com...
DLL = dynamic link library. This means that the library code is not
actually
linked into your executable, but remains in a separate file and is loaded
either
when you start the executable, or can actually be loaded on-request by the
program.


[snip]

It should be added that the OP's suspicion that his question might be
MS-specific, or at least platform-specific, was correct. None of this stuff
has anything to do with the C++ language.

DW

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Giles Brown | last post: by
5 posts views Thread by Marco Zapletal | last post: by
2 posts views Thread by Juan Martinez | last post: by
2 posts views Thread by mirandacascade | last post: by
reply views Thread by raludamian | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.