473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 2295

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Giles Brown | last post by:
I'm feeling quite dumb this morning. I'm trying to build a COM server DLL using py2exe and it ain't working. Here's what ain't working... setup_dll.py based on py2exe sample: """from...
3
by: mrzt | last post by:
the following codes won't work. ============================== using System; using System.Runtime; using System.Runtime.InteropServices; namespace Shutdown { /// <summary> /// Class1...
3
by: Dmitry Jouravlev | last post by:
Hi, I have a number of C++ solutions in Visual Studio .NET and when i compile them using "Whole Program Optimization", certain projects report a LNK1171 error saying that c2.dll could not be...
5
by: Marco Zapletal | last post by:
hi group, i am facing the following problem: i have a vs.net (c#) project, which compiles into a class library. now i wrote a kind of testcase (with a main method()) which i want to execute...
2
by: Juan Martinez | last post by:
In a form i have a drawing control called VectorDraw and a textbox. The text box is disable, when i am using the drawing area i can write some text, what i want to do is that when i press any key...
2
by: mirandacascade | last post by:
I am prompted to make these inquiries after seeing the following link to ctypes: http://docs.python.org/lib/module-ctypes.html in which ctypes is described as a foreign function library. ...
5
by: Jon E. Scott | last post by:
I'm a little confused with "static" methods and how to access other unstatic methods. I'm a little new to C#. I'm testing a callback routine within a DLL and the callback function returns a...
0
by: raludamian | last post by:
Hello! I'm trying to develop a GIS mapping software on smart devices (Pocket PC) using VS 2005, C#. I need to use a library that was written in C++. Being open source I compiled the C++ code...
13
by: Javad | last post by:
Hello I know that I should get the information of windows internet connections by using "rasapi32.dll" library, and I also have some sample codes, but I can't make them work. My exact need is to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.