none
What s difference b/w static linking & dynamic linking

    Question

  • Hi,
           Can anyone explain me about the difference b/w static linking & dynamic linking ? 

           Upto my knowledge there were two difference's

              1)  static linking means, if we do any changes to library part, we have to recompile the exe which loads that library, part also, but incase of dynamic linking, it is not necessary.

             2) Incase of static linking, there were a seperate library for each application which use it, but incase of dynamic linking, there will be only one dll and every application will share it

           Apart from this is there any difference ?

    Thanks
    Kiran
    Working as a software engineer
    Wednesday, October 08, 2008 6:32 AM

Answers

  •  The libraries can be linked to the executable in two ways . one is static linking and the other is dynamic linking. Static linking when building the program , the linker will search all the libraries for the unresolved functions called in the program and if found, it will copy the corresponding object code from the library and append it to the executable. It is easy to implementation but will generate bulky executable. In dynamic linking , the required functions are compiled and stored in a library with extension .DLL or exe here no object code is copied in to the executable from the libraries.Instead of when the executable is running , it will load the DLL and call the required functions from it. Thus we have a smaller executable .

    msdn

    A dynamic-link library (DLL) is an executable file that acts as a shared library of functions. Dynamic linking provides a way for a process to call a function that is not part of its executable code. The executable code for the function is located in a DLL, which contains one or more functions that are compiled, linked, and stored separately from the processes that use them. Only the information needed at run time to locate the executable code for a DLL function is in the executable module (either a .dll or .exe file). These libraries are "dynamically linked" because they are linked to an application when it is loaded and executed — rather than when it is created.

    In the case of static linking, the linker gets all of the referenced functions from the static link library and places it with your code into your executable file.


    Vikas
    • Marked as answer by jack 321 Tuesday, October 14, 2008 6:15 AM
    Wednesday, October 08, 2008 3:52 PM