Nelson Tatius
Nelson Tatius

Reputation: 8043

Difference between static library and relocatable object file?

What is the difference between static library and relocatable object file? Or between dynamic library and shared object file.

And if it's not equal things, what have dynamic library, that allows to link with it, but shared object file doesn't?

Upvotes: 9

Views: 4326

Answers (3)

Ron Pucul
Ron Pucul

Reputation: 1

Shard libraries save disk space if they are used by more than one executable. If multiple executable's that use the same function from a shared lib. are running each will get its own copy. Neither executable on disk will include that function's code but rather a reference to the shared lib.

Upvotes: 0

Ed Heal
Ed Heal

Reputation: 60007

Dynamic (shared) libraries uses PIC code - the code will work regardless of the actual physical location of the library that is used by multiple executables in memory.

Static libraries are linked into the executable during the linking phased to create the executable.

The advantage of dynamic libraries is the smaller footprint of the executable in memory. The advantage of static libraries is that you can just deliver the executable without the need to have the dynamic libraries and run a little faster and no effort is required to enable the library to exist anywhere in physical memory.

Upvotes: 1

Jerry Coffin
Jerry Coffin

Reputation: 490178

A static library is basically just a collection of object files. It's typically just an ar archive of object files. Using ar, you can extract object files from the library, add different object files to it, etc.

Generally speaking, the difference between a dynamic library and a shared object file is the target -- Windows uses dynamic libraries, Linux uses shared objects. There is a little more difference than that, but not a whole lot.

Upvotes: 7

Related Questions