The Wayback Machine - https://web.archive.org/web/20241118112957/https://www.geeksforgeeks.org/difference-between-static-and-shared-libraries/
Open In App

Difference between Static and Shared libraries

Last Updated : 15 Nov, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In programming, a library is a collection of pre-compiled pieces of code that can be reused in a program. Libraries simplify life for programmers, in that they provide reusable functions, routines, classes, data structures and so on which they can be reused in the programs. 

Static Libraries: A Static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable. This executable and the process of compiling it are both known as a static build of the program. Historically, libraries could only be static. They are usually faster than the shared libraries because a set of commonly used object files is put into a single library executable file. One can build multiple executables without the need to recompile the file. Because it is a single file to be built, use of link commands are simpler than shared library link commands, because you specify the name of the static library.

Shared Libraries: Shared libraries are .so (or in Windows .dll, or in OS X .dylib) files. These are linked dynamically simply including the address of the library (whereas static linking is a waste of space). Dynamic linking links the libraries at the run-time. Thus, all the functions are in a special place in memory space, and every program can access them, without having multiple copies of them.

properties Static library Shared library
Linking time It happens as the last step of the compilation process. After the program is placed in the memory Shared libraries are added during linking process when executable file and libraries are added to the memory.
Means Performed by linkers Performed by operating System
Size Static libraries are much bigger in size, because external programs are built in the executable file. Dynamic libraries are much smaller, because there is only one copy of dynamic library that is kept in memory.
External file changes Executable file will have to be recompiled if any changes were applied to external files. In shared libraries, no need to recompile the executable.
Time Takes longer to execute, because loading into the memory happens every time while executing. It is faster because shared library code is already in the memory.
Compatibility Never has compatibility issue, since all code is in one executable module. Programs are dependent on having a compatible library. Dependent program will not work if library gets removed from the system .


Previous Article
Next Article

Similar Reads

Difference between Shared Nothing Architecture and Shared Disk Architecture
1. Shared Nothing Architecture : Shared nothing architecture is an architecture that is used in distributed computing in which each node is independent and different nodes are interconnected by a network. Every node is made of a processor, main memory, and disk. The main motive of this architecture is to remove the contention among nodes. Here the
3 min read
Difference between static and non-static variables in Java
There are three types of variables in Java: Local VariablesInstance VariablesStatic Variables The Local variables and Instance variables are together called Non-Static variables. Hence it can also be said that the Java variables can be divided into 2 categories: Static Variables: When a variable is declared as static, then a single copy of the vari
4 min read
Difference Between Static and Non Static Nested Class in Java
Nested classes are divided into two categories namely static and non-static. Nested classes that are declared static are called static nested classes. Non-static nested classes are called inner classes. A class can either be static or non-static in java. So there is a lot of difference between making a class static or non-static. There are two kind
4 min read
Difference between Static-1 and Static-0 Hazard
A hazard in a digital circuit is a temporary disturbance in the ideal operation of the circuit which if given some time, gets resolved itself. These disturbances occur when different paths from the input to output have different delays. There are different kind of hazards but here we will discuss about the difference between different static hazard
3 min read
Difference between Shared Hosting and Dedicated Hosting
Prerequisite – Types of Web Hosting Web hosting is the main service required to get/post our information from a web server using a web browser. This serves as an address to retrieve the data located at this place form a large data-server. There are several options of web hosting, let us discuss the primarily used options when you get onto Web. 1. S
3 min read
Difference between Cloud hosting and Shared hosting
Prerequisite - Web hosting and its type and How to choose Web Hosting Server and Web Domain ? 1. Cloud hosting : Cloud hosting is one of the premium plan in the market for web hosting. Here the website is hosted on a set or a cluster of servers, many servers and machines are working synchronously as a single entity. Cloud hosting allows to create c
4 min read
Difference between Business Hosting, Shared Hosting and VPS Hosting
Business Hosting: Business Hosting, as the name suggests, is basically a web hosting package on a server provided to online business and e-commerce of all aspects, as well as shared among other users who purchased business hosting. It also allows individuals and organizations to make their websites accessible online. Features: Designed for business
5 min read
Difference between Shared Hosting and WordPress Hosting
Shared Hosting: Shared Hosting, as the name suggests, is basically a type of web hosting where the service provider provides web pages from more than one website and allows these websites to share a physical server connected to the internet. It stores website content on the server and makes it available to visitors whenever required. WordPress Host
2 min read
Difference between Shared Memory Model and Message Passing Model in IPC
Inter-Process Communication (IPC) is a critical aspect of modern operating systems, enabling processes to exchange data and synchronize their actions. Two primary models for IPC are the Shared Memory Model and the Message Passing Model. In the modern operating system, the Inter-Process Communication (IPC) is a very important element. It enables som
5 min read
Difference between Shared Lock and Exclusive Lock
Ensuring Data Integrity and Isolation is essential when numerous transactions are accessing a database at once to avoid conflicts and preserve correctness. Locks are a typical way to manage access to data elements in a transaction, thereby guaranteeing the isolation characteristic. Locks are systems that stop many transactions from making changes t
7 min read
Difference between Time Shared Bus, Crossbar Switch & Multiport Memory - Interconnection structure
Interconnection structure can decide the overall system's performance in a multi-processor environment. The processors must be able to share a set of main memory modules & I/O devices in a multiprocessor system. This sharing capability can be provided through interconnection structures. The interconnection structure that are commonly used can b
5 min read
Internal static variable vs. External static variable with Examples in C
The static variable may be internal or external depending on the place of declaration. Both kinds of static variables are stored in initialized data segments. Internal Static Variables Internal Static variables are defined as those having static variables which are declared inside a function and extend up to the end of the particular function. Synt
2 min read
Difference Between AndroidX and Android Support Libraries
Support library packages in Android are a set of code libraries whose prime purpose is to provide backward-compatibility to the code and Android API framework. In the real world, there is a strong possibility that an application that is developed on the latest Android version is used on an older version of Android OS. Thus, including the support li
3 min read
fork() and memory shared b/w processes created using it
Prerequisite: fork() in C So when we do a fork() what are the sections the two process actually share? Is the heap memory per process? Are the global variables shared? Will malloc return the same address to both? Let us run the program below and take a look at the output of it to clear the questions above. C/C++ Code // C program to demonstrate wor
4 min read
IPC through shared memory
Inter-Process Communication (IPC) is a fundamental concept in operating systems that allows multiple processes to communicate and synchronize their actions. Among the various methods of IPC shared memory is one of the most efficient mechanisms especially when it comes to performance-critical applications. This article delves into the concept of IPC
7 min read
Difference between Static and Dynamic SQL
Static or Embedded SQL are SQL statements in an application that do not change at runtime and, therefore, can be hard-coded into the application. Dynamic SQL is SQL statements that are constructed at runtime; for example, the application may allow users to enter their own queries. Dynamic SQL is a programming technique that enables you to build SQL
2 min read
Difference between Static variables and Register variables in C
static variables Static variables have a property of preserving their value even after they are out of their scope! Hence, static variables preserve their previous value in their previous scope and are not initialized again in the new scope. Syntax: static data_type var_name = var_value; register variables Registers are faster than memory to access
2 min read
Difference between Static and Friend Function in C++
Static Function: It is basically a member function that can be called even when the object of the class is not initialized. These functions are associated with any object and are used to maintain a single copy of the class member function across different objects of the class. This function is denoted by using the static keyword. Friend Function: I
3 min read
Difference Between Constructor and Static Factory Method in Java
Whenever we are creating an object some piece of code will be executed to perform initialization of that object. This piece of code is nothing but a constructor, hence the main purpose of the constructor is to perform initialization of an object but not to create an object. Let us go through the basic set of rules for writing a constructor. They ar
4 min read
Difference Between Singleton Pattern and Static Class in Java
Singleton Pattern belongs to Creational type pattern. As the name suggests, the creational design type deals with object creation mechanisms. Basically, to simplify this, creational pattern explains to us the creation of objects in a manner suitable to a given situation. Singleton design pattern is used when we need to ensure that only one object o
6 min read
Difference between Static Friction and Dynamic Friction
Friction is defined as the force that opposes the motion between any surfaces, fluid layers, and any other material in contact with each other. Friction is produced due to the irregularities between the surfaces. It produces heat. It depends on the nature of the surfaces. Friction always acts between any two contact surfaces of bodies. Friction is
6 min read
Difference between Static allocation and Stack allocation
Static Allocation: Static allocation is a procedure which is used for allocation of all the data objects at compile time. Static allocation is possible only when the compiler knows the size of data object at compile time. In this type of allocation, formation of data objects is not possible under any circumstances at run time. In static allocation,
2 min read
Difference Between Static and Dynamic Web Pages
There are two basic methods of web design: static and dynamic web pages. Users access static web pages, which present the same content every time they are viewed. On the other hand, dynamic webpages create content instantly in response to user input and present customized or updated information. Let's learn about this in detail in this article. Wha
3 min read
Difference between Static and Dynamic IP address
As you discuss connectivity of devices to the internet, or communication within a network, an IP address is taken as a basic understanding. There are two main types of IP addresses: Static and Dynamic. The purpose of this article is to describe what IP addresses are and the difference between static and dynamic IPs. What is IP Address?IP stands for
6 min read
Difference between Static and Dynamic Hazard
Hazard: In digital circuits, specially in combinational circuits, they give rise to behavior's, glitches and/or wrong output signals. While designing electronics circuits, one must be in a position to distinguish between the static hazards and dynamic hazards. Interference or interruption occurs when due to race condition the signal passes through
4 min read
Difference Between Static Allocation and Heap Allocation
In programming, there are two approaches to memory management and these are static allocation and heap allocation. In static allocation, memory is determined at the compile time, where the size and position of each data structure for example arrays, variable are constant throughout the program. While this approach may help to give faster access, it
5 min read
Difference between Static and Dynamic Routing
Routing is a vital communication mechanism that governs how data packets travel from source to destination. Effective routing ensures that data is transferred across networks in an efficient, reliable, and timely manner. There are two main forms of routing: static and dynamic. In this article, we will discuss the differences between static and dyna
4 min read
Difference between Static and Dynamic Memory Allocation in C
Memory Allocation: Memory allocation is a process by which computer programs and services are assigned with physical or virtual memory space. The memory allocation is done either before or at the time of program execution. There are two types of memory allocations: Compile-time or Static Memory AllocationRun-time or Dynamic Memory AllocationStatic
3 min read
Difference Between Static andDynamic Loading in Operating System
An operating system is a program loaded into a system or computer. and manage all the other program which is running on that OS Program, it manages the all other application programs. or in other words, we can say that the OS is an interface between the user and computer hardware. Static Loading in OS In static loading, Initially, the complete prog
5 min read
Initialization of global and static variables in C
Predict the output of following C programs. // PROGRAM 1 #include <stdio.h> #include <stdlib.h> int main(void) { static int *p = (int*)malloc(sizeof(p)); *p = 10; printf("%d", *p); } // PROGRAM 2 #include <stdio.h> #include <stdlib.h> int *p = (int*)malloc(sizeof(p)); int main(void) { *p = 10; printf("%d"
1 min read
three90RightbarBannerImg