Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 478
Nelson Tatius Avatar asked Mar 16 '12 17:03

Nelson Tatius


People also ask

What is the difference between relocatable object file and executable file?

A relocatable file holds code and data suitable for linking with other object files to create an executable or a shared object file. An executable file holds a program suitable for execution; the file specifies how exec (BA_OS) creates a program's process image.

What is relocatable object file?

A relocatable object file holds sections containing code and data. This file is suitable to be linked with other relocatable object files to create dynamic executable files, shared object files, or another relocatable object. A dynamic executable file holds a program that is ready to execute.

What is a static library file?

What Does Static Library Mean? A static library is a programming concept in which shared libraries with special functionalities, classes or resources are linked to external applications or components, facilitating the creation of stand-alone and executable files.

What is the difference between static library and shared library?

Static libraries take longer to execute, because loading into the memory happens every time while executing. While Shared libraries are faster because shared library code is already in the memory. In Static library no compatibility issue has been observed.


2 Answers

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.

like image 149
Jerry Coffin Avatar answered Oct 07 '22 17:10

Jerry Coffin


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.

like image 37
Ed Heal Avatar answered Oct 07 '22 18:10

Ed Heal