[go: up one dir, main page]

0% found this document useful (0 votes)
6 views2 pages

11 - Dynamic Vs Static Links

The document explains the role of linkers in compiling programs, detailing static and dynamic linking. Static linking incorporates all library routines into the executable, making it faster and more portable but larger in size, while dynamic linking allows sharing of libraries among programs, reducing resource consumption and enabling easier updates. Each method has its advantages and disadvantages, influencing their use in different environments and scenarios.

Uploaded by

Jordi Puig
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

11 - Dynamic Vs Static Links

The document explains the role of linkers in compiling programs, detailing static and dynamic linking. Static linking incorporates all library routines into the executable, making it faster and more portable but larger in size, while dynamic linking allows sharing of libraries among programs, reducing resource consumption and enabling easier updates. Each method has its advantages and disadvantages, influencing their use in different environments and scenarios.

Uploaded by

Jordi Puig
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

http://stackoverflow.

com/questions/1993390/static-linking-vs-dynamic-linking

What is a linker, and


what are dynamic and
static linking?
Link editors are commonly known as linkers. The compiler
automatically invokes the linker as the last step in compiling a
program. The linker inserts code (or maps in shared libraries) to
resolve program library references, and/or combines object
modules into an executable image suitable for loading into
memory. On Unix-like systems, the linker is typically invoked
with the ld command.

Static linking is the result of the linker copying all library


routines used in the program into the executable image. This
may require more disk space and memory than dynamic
linking, but is both faster and more portable, since it does not
require the presence of the library on the system where it is
run.

Dynamic linking is accomplished by placing the name of a


sharable library in the executable image. Actual linking with the
library routines does not occur until the image is run, when
both the executable and the library are placed in memory. An
advantage of dynamic linking is that multiple programs can
share a single copy of the library.

• Dynamic linking can reduce total resource


consumption (if more than one process shares the same
library (including the version in "the same", of course)). I
believe this is the argument that drives it its presence in
most environments. Here "resources" includes disk space,
RAM, and cache space. Of course, if your dynamic linker is
insufficiently flexible there is a risk of DLL hell.
• Dynamic linking means that bug fixes and upgrades to
libraries propagate to improve your product without
requiring you to ship anything.
• Dynamic linking is the only practical way to meet some
license requirements such as the LGPL.
• Plugins always call for dynamic linking.

• Static linking, means that you can know the code will run
in very limited environments (early in the boot process,
or in rescue mode).
• Static linking can make binaries easier to distribute to
diverse user environments (at the cost of sending a large
and more resource hungry program).
• Static linking may allow slightly faster startup times, but
this depends to some degree on both the size and
complexity of your program and on the details of the OSs
loading strategy.

You might also like