shota silagadze
shota silagadze

Reputation: 173

Linking dynamic library

I want to know exactly how the process of linking works in case of dynamic library. As I already know it first loads the image/binary in memory and (for every program calling/linking for the library) it's called. but my question is the following: how the program distinguishes the shared and static libraries? only just by .so and .a? if I link the full path of the dynamic library like /path/to/so/file.so it sounds silly but does it become static and the content is copied into executable binary?

Thanks ...

Upvotes: 0

Views: 185

Answers (1)

mn1
mn1

Reputation: 440

No, Providing the linker with a full path doesn't turn the library into a static one. The "decision" which code will be part of the binary happens at compile time. When the binary is loaded the loader can load additional libraries (dynamic) but they are not part of the binary itself (i.e. the size of the binary will not change after compilation is done).

The loader can tell the difference between a static and dynamic library by examining the library's object file. This file is generated in the compilation process (for example using "-shared" on Linux gcc), i.e. compiled static libraries has different object file format than dynamically compiled libraries.

Providing a full path to the linker is related to the way the linker is searching for the library file for compilation (or later on the loader when it is looking for the shared library on the system). It does not affect the type of the library (which was already "chosen" when it was compiled).

Upvotes: 2

Related Questions