user1872473
user1872473

Reputation: 43

Static and Dynamic Linking Libraries

I have some Questions on linking libraries.

How does the Linker decide, if a library I want to link is linked static or dynamic? Is it decided by the file extention (.a/.so)?

Is it possible, to dynamically link a .a library?

Is it possible to convert a .a library into a .so library without having the sources?

Upvotes: 1

Views: 595

Answers (2)

fig
fig

Reputation: 813

The gcc linker will link dynamically to .so files by default, if both types of library are found in its search path. You can over-ride this with command line arguments, as described here.

Upvotes: 0

Tom Tanner
Tom Tanner

Reputation: 9354

  1. The linker decides how to link the library by generally looking at the extension, but that's pretty much up to the linker. The AIX linker has some rather exotic behaviour. Moreover, if you have both a .so and a .so version of the library in the same place, the command line switches you have given the linker will determine which one it uses
  2. Sort of. You can link a .a into a .so but there will be performance issues - shared libraries should be built with position independent code for best performance. And depending on the code, the linker might refuse to link it because it can't patch up the relocation information. But you can't tell the linker to treat a .a as a .so
  3. As above - maybe.

Upvotes: 1

Related Questions