473,748 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static library and dynamic library

Hi all,

As far as I know, relative address will be assigned by program at link
time.Right? Ok, here we go.

So if we use a static library, it will give the program an relative
address(i mean the function address) at link time.
Also the code of the library will load into the program. Go on.

Now if we use a dynamic library, what it will give the program?
A symbolic? or Address ?

if it is a symbolic, when does the symbolic change to an address? and
How does it load its code to the program?
Thanks
Even

Oct 18 '07 #1
6 5619
Even <sz****@winbond .comwrote:
As far as I know, relative address will be assigned by program at link
time.Right?
Or wrong. Or pale blue with dots. All this is entirely system-dependent.
It may even be (but possibly isn't) compiler-dependent. You'll have to
ask this question in a newsgroup that specialises in your OS (somewhere
in microsoft.publi c.*, by the looks of it), and there you'll probably
need to specify which compiler you're using as well.

Richard
Oct 18 '07 #2
Even wrote:
Hi all,

As far as I know, relative address will be assigned by program at link
time.Right? Ok, here we go.

So if we use a static library, it will give the program an relative
address(i mean the function address) at link time.
Also the code of the library will load into the program. Go on.

Now if we use a dynamic library, what it will give the program?
A symbolic? or Address ?

if it is a symbolic, when does the symbolic change to an address? and
How does it load its code to the program?
Thanks
Even
Under the windows system, dynamic link libraries are
relocated to some address at load time. The linker
produces a relocation table that allows loading the
library at any address

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Oct 18 '07 #3

"Even" <sz****@winbond .comwrote in message
news:11******** **************@ e34g2000pro.goo glegroups.com.. .
Hi all,

As far as I know, relative address will be assigned by program at link
time.Right? Ok, here we go.
'relative' is not a good term here.

So if we use a static library, it will give the program an relative
address(i mean the function address) at link time.
Also the code of the library will load into the program. Go on.
yeah, at link time, all the code and data from the library goes into the
binary, which is part of why using lots of static libs tends to produce
large binaries...

the code in the app is linked directly to the code in the library, just the
same as with local code.

Now if we use a dynamic library, what it will give the program?
A symbolic? or Address ?
it depends.

if it is a symbolic, when does the symbolic change to an address? and
How does it load its code to the program?
this depends on the OS.

note that there may be errors here, all this is not something I have looked
into in too much detail.
on linux and friends, it will produce a binary that is like "oh well, I am
not fully linked, load these libraries on loading". so, the loader will also
grab the libraries, and resolve the addresses to the addresses in the
library (internally, this will look about the same as if the app had used a
static library).

the exact mechanics of this process are not something I will really go into.

note that in linux, these libs tend to use position-independent-code, which
is fun, since the same library pages can be shared between different
processes, and located at different locations in each (GOT magic...). in
windows, however, DLLs are typically fixed-address to allow sharing
(relocating DLLs is also possible, but they end up having their own pages in
each process...).
now, I think, DLLs are a little different.
as far as I understand it, with DLLs you end up with a number of proxy
functions, which jump into the function through a jump table.

so, at load time, the app is loaded, and either the loader (or part of the
app's runtime, or at least, I think this is how it worked at one time) sees
that a DLL is needed, so it loads the DLL and fills in the various slots in
the table.

in the past, this was done via import libraries (a special tool was used to
make a static library from the DLL), but (at least for GNU-ld), all this
magic is done by the linker itself.

but, none of this is anything I have really looked into in too much
detail...

>
Thanks
Even
Oct 18 '07 #4
Thanks for your all reply, especially cr88192.

That is, in linux different processes share the the same code(Dlls),
but in window they copy the code to their space.

Now we have a global variable(g_var) in Dlls, in linux if one process
change the *g_var*, and does it effect another process?

by the way, what's the different between 'load time' and 'running
time'. Does 'OS' control 'load time'?

Oct 19 '07 #5

"Even" <sz****@winbond .comwrote in message
news:11******** **************@ t8g2000prg.goog legroups.com...
Thanks for your all reply, especially cr88192.

That is, in linux different processes share the the same code(Dlls),
but in window they copy the code to their space.
linux usually shares code. this is because shared-objects tend to be
compiled with position-independent-code.

windows tries to share pages, but does not if the hard-coded address can't
be used (many DLLs are pre-relocated to be loaded at certain addresses...).
Now we have a global variable(g_var) in Dlls, in linux if one process
change the *g_var*, and does it effect another process?
probably, linux likely handles shared libraries similar to, fork(), namely
that any shared pages are copy-on-write.
by the way, what's the different between 'load time' and 'running
time'. Does 'OS' control 'load time'?
load time is, when the app is being loaded. runtime generally means
"whenever the app so feels like it".
yes, usually load-time is OS controlled.
or such...

Oct 19 '07 #6
On Fri, 19 Oct 2007 21:29:37 +1000, in comp.lang.c , "cr88192"
<cr*****@nospam .hotmail.comwro te:
>
"Even" <sz****@winbond .comwrote in message
news:11******* *************** @t8g2000prg.goo glegroups.com.. .
>Thanks for your all reply, especially cr88192.

That is, in linux different processes share the the same code(Dlls),
but in window they copy the code to their space.

linux usually shares code. this is because shared-objects tend to be
compiled with position-independent-code.
Would you please stop answering this highly-offtopic question in CLC?
The OP will start to think they can get all their programming
questions answered here, and next time it may be even more wildly
offtopic
>windows tries to share pages, but does not if the hard-coded address can't
be used (many DLLs are pre-relocated to be loaded at certain addresses...).
And please don't say "well ,where /can/ you ask about windows _and_
linux at the same time" because thats not relevant. I've no idea where
you ask about bondage _and_ buddism at the same time, but that doesn't
make it topical in CLC ....

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 20 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3832
by: iceColdFire | last post by:
Hi, Can someone highlight the difference between static library and bynamic library...and how do .lib and .dll files come up in the picture... Thanks, a.a.cpp++ :-)
1
6966
by: Eduardo Suárez | last post by:
Hi, i have tried to understand how static variables work on a dynamic library, but there's a point i can't see. * Is the data segment (where static variables live, please confirm) copied for every binary that is running linked to the library? This is what it seems from my own experiments. That is, there is a copy of every static variable for every binary linked. Then, is it really useful the library?
6
2598
by: Andrew S. Giles | last post by:
Is it possible to bring in a static library (developed in C++) into a C# project/solution? Thanks in advance for any information. Andrew S. GIles
5
1885
by: meendar | last post by:
can anyone tell me what the static and dynamic library? thnkx in advance.
5
5097
by: info | last post by:
Hi! Please be patient with a newbie... I use DevC++. I've found and compiled succefully various openGL examples. Before build the application, I link the project with static libs, like, in example, libglut32.a. The executables running fine, but if I try them on a system without glut32.dll, they don't start.
14
17830
by: Shimon Sim | last post by:
I have a static variable defined something like this private static Dictionary<string, string> roles = new Dictionary<string,string>(); Can I safely assume that it will be live for the live of application? Meaning that any thread/page of the application will have access to the data in this variable.
20
6094
by: JohnQ | last post by:
The way I understand the startup of a C++ program is: A.) The stuff that happens before the entry point. B.) The stuff that happens between the entry point and the calling of main(). C.) main(). So, if the above is OK, does static initialization occur during A or B? What happens during A?
4
1977
by: sealo | last post by:
Hello, I have a test in VS2005 that static library A.lib use the dynamic library C.dll. Then a application App use the A.lib. App-->A.lib-->C.dll It works. But if I remove the C.dll, the app tell me can not find the C.dll. I think because A.lib is a static library, so it should contain the
4
3707
by: kukuta | last post by:
Hi I have static library that is created from VC++.Net, however, I would like to use it in Borland C++ and I do any ways but it is not successful. So I want to ask: by the way can I use static library in Borland C++? Or can I change the static library into dynamic library? If the second way can be, can you tell me the ways? If any ways above cannot do, please show me another way. Thanks alot. Any instructions and any ideas are very...
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6798
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6077
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.