Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between static linking and dynamic linking

Tags:

dll

What is the difference between static linking and dynamic linking?

like image 271
anand Avatar asked Nov 11 '10 11:11

anand


People also ask

What is the difference between a dynamic and static library?

What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.

What is the difference between dynamic loading and linking?

Dynamic loading means loading the library (or any other binary for that matter) into the memory during load or run-time. Dynamic linking refers to the linking that is done during load or run-time and not when the exe is created.

What do you mean by static linking?

Static linking means that the code for all routines called by your program becomes part of the executable file. Statically linked programs can be moved to run on systems without the XL Fortran runtime libraries.

What is statically linked and dynamically linked libraries?

Statically-linked files are 'locked' to the executable at link time so they never change. A dynamically linked file referenced by an executable can change just by replacing the file on the disk. This allows updates to functionality without having to re-link the code; the loader re-links every time you run it.


2 Answers

In static linking, functions and variables which are defined in external library files are linked inside your executable. That means that the code is actually linked against your code when compiling/linking.

With dynamic linking external functions that you use in your software are not linked against your executable. Instead they reside in a external library files which are only referenced by your software. Ie: the compiler/linker instructs the software on where to find the used functions.

On windows platforms you can even explicitly load DLL files at run time and hook up the functions contained in the DLL.

like image 125
Dexter Avatar answered Sep 25 '22 06:09

Dexter


Static linking is done at 'compile time' by a tool called a linker. Dynamic linking is done at run time, by the operating system.

like image 21
Will Dean Avatar answered Sep 23 '22 06:09

Will Dean