Home c++ What's the difference between static and dynamic linking?

What’s the difference between static and dynamic linking?

Author

Date

Category

What’s the difference between static and dynamic linking?

Why, when these phrases are googled, the result is given about static and dynamic libraries? Is it the same thing, or is it the same thing happening?

And how is this then related to linking the object file: for example, I wrote the code, it went through the stages of preprocessor, compilation and appearance of the object file, and then linking. And how then to understand how the object file in the .exe is linked in VS: dynamically or statically?
But the main question is: what is the difference between static and dynamic linking?


Answer 1, authority 100%

Everything was displayed correctly for you.
Linking (well, or linking) is the last stage of the build. Everything that happens at this stage is subject to the linker script.

Closer to the body:

When you build your project and want to include a library in it (built Statically or Dynamically * .a or * .so) all your code is linked ld. When you write somewhere that a function of library A will be called here, the compiler leaves there a mark (in fact, a promise) that the reference to the call data will be substituted at the linking stage. Next, the cheater looks at the SHARED or STATIC bind flags (which is responsible for a dynamic or static library) and searches for it according to the standard paths and / or the paths you specify.

Static library – (* .a) compiled for direct embedding into your executable file. It will simply be placed as specified by the linker.
There will be static linking here.

Dynamic library – (* .so) – will simply be connected as a link to the reference and will not be included in your binaries. There will only be an indication of where to get the reference for this or that functionality. There will be dynamic linking here.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions