SlideShare a Scribd company logo
Libraries
16/05/15 2
Library:
• It may contain a group of functions that are used in a particular
context.
• Functions which can be shared by more than one applications
are broken out of the application’s source code, compiled and
bundled into a library.
Types :
• Static
• Dynamic/Shared
16/05/15 3
Static Library(archives) (extension- .a):
• Every executable program have a copy of library code.
Dynamically linked shared object libraries(extension- .so):
• Dynamically loaded/unloaded and linking during execution
using the dynamic linking loader system functions.
• The shared objects are not included into the executable
component but are tied to the execution.
16/05/15 4
Static Library
•Typically named with the prefix “lib”.
For example:
Math library - libmath.a (static)
Shared Library
●Name used by linker - libmath.so
●Fully qualified name or soname - libpthread.so.1
●Real name - libpthread.so.1.1
Version
Number
Minor Number
Library Naming Convention
16/05/15 5
Location in File System
- According to File Heirarchy Standards
• /lib - loaded at startup
• /usr/lib - used by system internally
• /usr/local/lib - non standard distribution
Usage of ldconfig
Linker
Symbolic
link
Fully Qualified
“soname”
16/05/15 6
• ar is an archive tool used to combine objects to create an
archive file with .a extension, i.e, library.
1) Create 2 sample C programs
2) Compile the programs and get the object code
3) Create the C program static library using ar utility
4) Write C program to use the library libarith.a
Steps to Create Static Library
16/05/15 7
1) Create two sample C programs:
int addition(int a, int b) int multiplication( int a, int b)
{ {
int result; int result;
result=a+b; result=a*b;
} }
2) Compile and get object codes:
$ gcc –c addition.c
$ gcc –c multiplication.c
Current working directory contains both c and object files.
$ ls
addition.c multiplication.c addition.o multiplication.o
16/05/15 8
3) Create the C program Static Library using ar utility:
$ ar cr libarith.a addition.o multiplication.o
4) Write c program to use the library libarith.a:
Create header.h Create example.c:
#include<stdio.h> #include “header.h”
Int addition(int a, int b); int main()
Int multiplication(int a, intb); {
int result;
result=addition(1,2);
printf(“addition result is :
%dn”
, result);
result=multiplication(3,2);
printf(“multiplication result is :
%dn”, result);
16/05/15 9
• Compile example.c
$ gcc –Wall example.c libarith.a –o example
Result:
$ ./example
addition result is :3
multiplication result is : 6
16/05/15 10
To Command Result
List Object Files $ ar t libarith.a addition.o
multiplication.o
Extract object files from
archive
$ ar x libarith.a
$ ls *.o
Addition.o
Multiplication.o
Add object file into existing
archive file
$ ar r libarith.a subtraction.o Addition.o
Multiplication.o
Subtraction.o
Delete the specific archive
member
$ ar d libarith.a addition.o Multiplication.o
Subtraction.o
16/05/15 11
1. Create code that has to be added to Shared Library
2. Create a header file
3. Create a shared library
4. Write a program which uses shared library
5. Link the code with shared library
6. Set the environment variable
7. Run the program
Steps to Create Shared Library
16/05/15 12
Step 1. shared.c:
#include “shared.h”
Unsigned int add(unsigned int a, unsigned int b)
{
Printf(“n Inside add()n”);
Return(a+b);
}
Step 2. Shared.h:
#include<stdio.h>
extern unsigned int add(unsigned int a, unsigned int b);
16/05/15 13
Step 3.
gcc –c –Wall – werror –fPIC shared.c
gcc –shared –o libshared.so shared.o
Step 4.
#include<stdio.h>
#include”shared.h”
int main(void)
{
unsigned int a=1;
unsigned int b=2;
unsigned int result =0;
result=add(a,b);
printf(“n the result is [%u]n”, result);
return 0;
}
16/05/15 14
Step 5.
gcc –L/home/Desktop/practice/ -wall main.c –o main –lshared
Step 6.
export LD_LIBRARY_PATH=/home/desktop/practice:$
LD_LIBRARY_PATH
Step 7.
$ ./main
Inside add()
The result is [3]
16/05/15 15
16/05/15 16
Static Library Shared Library
Increased memory for each program Contains a record of
1. Name of the symbol
2. Which library is it from
Time Consuming Time Efficient
Re-linking difficulties Run time linking using Fully Qualified
soname
Run time Execution is relatively fast Run time Execution is relatively slow
Objects of unresolved symbols get
copied to the address space
Shared library is mapped to address space
of program
Extension - .a Extensions - .so(.x.x)
Difference b/w Static & Shared Library
16/05/15 17
How Static Library Works?
File a.o b.o Libx.a Liby.a
Object a.o b.o X1.o X2.o Y1.o Y2.o
Definitions a1,a2,A3 b1,B2,b3 x11,X12 X21,x22 y11,Y12 y21,
Y22
Undefined
refernce
b2,x12 a3,y22 x23,y12 y11 y21
16/05/15 18
int e=7;
int main() {
int r = a();
exit(0);
}
main.c
add.c
extern int e;
int *ep=&e;
int x=15;
int y;
int a() {
return *ep+x+y;
}
How Shared Library Works?
16/05/15 19
Merging .o files into an executable
int e = 7
headers
system code
main()
a()
int *ep = &e
more system code
system data
int x = 15
.text
.data
uninitialized data .bss
.symtab
.debug
system code
system data
.text
.data & .bss
main()main.o
int e = 7
.text
.data
add.o
int *ep = &e
a()
int x = 15
int y
.text
.data
.bss
a()
Relocatable object files
0
Executable object files
16/05/15 20
“by Sriee Gowthem Raaj”

More Related Content

What's hot

Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
shimosawa
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)
Brendan Gregg
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
ICI Bucharest - roTLD
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Knoldus Inc.
 
CMake best practices
CMake best practicesCMake best practices
CMake best practices
Henry Schreiner
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
mcganesh
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Manav Prasad
 
Linux User Management
Linux User ManagementLinux User Management
Linux User Management
Gaurav Mishra
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux Kernel
Adrian Huang
 
GitHub Presentation
GitHub PresentationGitHub Presentation
GitHub Presentation
BrianSchilder
 
Reverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelReverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux Kernel
Adrian Huang
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
Chandan Kumar Rana
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
QUONTRASOLUTIONS
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
Divye Kapoor
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
Jian-Hong Pan
 
NFS(Network File System)
NFS(Network File System)NFS(Network File System)
NFS(Network File System)
udamale
 
DMA Survival Guide
DMA Survival GuideDMA Survival Guide
DMA Survival Guide
Kernel TLV
 
Chapter03 Creating And Managing User Accounts
Chapter03      Creating And  Managing  User  AccountsChapter03      Creating And  Managing  User  Accounts
Chapter03 Creating And Managing User Accounts
Raja Waseem Akhtar
 
Understanding The Boot Process
Understanding The Boot ProcessUnderstanding The Boot Process
Understanding The Boot Process
Dominique Cimafranca
 
X / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural OverviewX / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural Overview
Moriyoshi Koizumi
 

What's hot (20)

Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
CMake best practices
CMake best practicesCMake best practices
CMake best practices
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Linux User Management
Linux User ManagementLinux User Management
Linux User Management
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux Kernel
 
GitHub Presentation
GitHub PresentationGitHub Presentation
GitHub Presentation
 
Reverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelReverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux Kernel
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
NFS(Network File System)
NFS(Network File System)NFS(Network File System)
NFS(Network File System)
 
DMA Survival Guide
DMA Survival GuideDMA Survival Guide
DMA Survival Guide
 
Chapter03 Creating And Managing User Accounts
Chapter03      Creating And  Managing  User  AccountsChapter03      Creating And  Managing  User  Accounts
Chapter03 Creating And Managing User Accounts
 
Understanding The Boot Process
Understanding The Boot ProcessUnderstanding The Boot Process
Understanding The Boot Process
 
X / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural OverviewX / DRM (Direct Rendering Manager) Architectural Overview
X / DRM (Direct Rendering Manager) Architectural Overview
 

Similar to Libraries

Linkers
LinkersLinkers
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotools
Thierry Gayet
 
Autotools
AutotoolsAutotools
Autotools
Thierry Gayet
 
Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical training
Thierry Gayet
 
C Under Linux
C Under LinuxC Under Linux
C Under Linux
mohan43u
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
guestd9065
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Ahmed El-Arabawy
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Diego Freniche Brito
 
Build your own discovery index of scholary e-resources
Build your own discovery index of scholary e-resourcesBuild your own discovery index of scholary e-resources
Build your own discovery index of scholary e-resources
Martin Czygan
 
Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]
Benny Siegert
 
Lecture 8_Libraries.pptx
Lecture 8_Libraries.pptxLecture 8_Libraries.pptx
Lecture 8_Libraries.pptx
NelyJay
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
Eelco Visser
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
Andrii Soldatenko
 
Understanding how C program works
Understanding how C program worksUnderstanding how C program works
Understanding how C program works
MindBridgeTech
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
Deepak Chandani
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oS
Harrytoye2
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
farishah
 
Libraries
LibrariesLibraries
Libraries
Ashwanth Selvam
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
bhargavi804095
 

Similar to Libraries (20)

Linkers
LinkersLinkers
Linkers
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotools
 
Autotools
AutotoolsAutotools
Autotools
 
Autotools pratical training
Autotools pratical trainingAutotools pratical training
Autotools pratical training
 
C Under Linux
C Under LinuxC Under Linux
C Under Linux
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Build your own discovery index of scholary e-resources
Build your own discovery index of scholary e-resourcesBuild your own discovery index of scholary e-resources
Build your own discovery index of scholary e-resources
 
Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]
 
Lecture 8_Libraries.pptx
Lecture 8_Libraries.pptxLecture 8_Libraries.pptx
Lecture 8_Libraries.pptx
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
Understanding how C program works
Understanding how C program worksUnderstanding how C program works
Understanding how C program works
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oS
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
Libraries
LibrariesLibraries
Libraries
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
 

More from University of Texas at Dallas

Interaction overview & Timing diagram
Interaction overview & Timing diagramInteraction overview & Timing diagram
Interaction overview & Timing diagram
University of Texas at Dallas
 
Communication Diagram
Communication DiagramCommunication Diagram
Communication Diagram
University of Texas at Dallas
 
Sequence Diagram
Sequence DiagramSequence Diagram
State Diagram
State DiagramState Diagram
Package Diagram
Package DiagramPackage Diagram
Deployment Diagram
Deployment DiagramDeployment Diagram
Deployment Diagram
University of Texas at Dallas
 
Component Diagram
Component DiagramComponent Diagram
Composite Structure Diagram
Composite Structure DiagramComposite Structure Diagram
Composite Structure Diagram
University of Texas at Dallas
 
Object diagram
Object diagramObject diagram
Class diagram
Class diagramClass diagram
Use Case UML Diagram
Use Case UML DiagramUse Case UML Diagram
Use Case UML Diagram
University of Texas at Dallas
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
University of Texas at Dallas
 
Yocto project
Yocto projectYocto project
Subversion Reference
Subversion ReferenceSubversion Reference
Subversion Reference
University of Texas at Dallas
 
Subversion
SubversionSubversion

More from University of Texas at Dallas (15)

Interaction overview & Timing diagram
Interaction overview & Timing diagramInteraction overview & Timing diagram
Interaction overview & Timing diagram
 
Communication Diagram
Communication DiagramCommunication Diagram
Communication Diagram
 
Sequence Diagram
Sequence DiagramSequence Diagram
Sequence Diagram
 
State Diagram
State DiagramState Diagram
State Diagram
 
Package Diagram
Package DiagramPackage Diagram
Package Diagram
 
Deployment Diagram
Deployment DiagramDeployment Diagram
Deployment Diagram
 
Component Diagram
Component DiagramComponent Diagram
Component Diagram
 
Composite Structure Diagram
Composite Structure DiagramComposite Structure Diagram
Composite Structure Diagram
 
Object diagram
Object diagramObject diagram
Object diagram
 
Class diagram
Class diagramClass diagram
Class diagram
 
Use Case UML Diagram
Use Case UML DiagramUse Case UML Diagram
Use Case UML Diagram
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Yocto project
Yocto projectYocto project
Yocto project
 
Subversion Reference
Subversion ReferenceSubversion Reference
Subversion Reference
 
Subversion
SubversionSubversion
Subversion
 

Recently uploaded

Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 

Recently uploaded (20)

Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 

Libraries

  • 2. 16/05/15 2 Library: • It may contain a group of functions that are used in a particular context. • Functions which can be shared by more than one applications are broken out of the application’s source code, compiled and bundled into a library. Types : • Static • Dynamic/Shared
  • 3. 16/05/15 3 Static Library(archives) (extension- .a): • Every executable program have a copy of library code. Dynamically linked shared object libraries(extension- .so): • Dynamically loaded/unloaded and linking during execution using the dynamic linking loader system functions. • The shared objects are not included into the executable component but are tied to the execution.
  • 4. 16/05/15 4 Static Library •Typically named with the prefix “lib”. For example: Math library - libmath.a (static) Shared Library ●Name used by linker - libmath.so ●Fully qualified name or soname - libpthread.so.1 ●Real name - libpthread.so.1.1 Version Number Minor Number Library Naming Convention
  • 5. 16/05/15 5 Location in File System - According to File Heirarchy Standards • /lib - loaded at startup • /usr/lib - used by system internally • /usr/local/lib - non standard distribution Usage of ldconfig Linker Symbolic link Fully Qualified “soname”
  • 6. 16/05/15 6 • ar is an archive tool used to combine objects to create an archive file with .a extension, i.e, library. 1) Create 2 sample C programs 2) Compile the programs and get the object code 3) Create the C program static library using ar utility 4) Write C program to use the library libarith.a Steps to Create Static Library
  • 7. 16/05/15 7 1) Create two sample C programs: int addition(int a, int b) int multiplication( int a, int b) { { int result; int result; result=a+b; result=a*b; } } 2) Compile and get object codes: $ gcc –c addition.c $ gcc –c multiplication.c Current working directory contains both c and object files. $ ls addition.c multiplication.c addition.o multiplication.o
  • 8. 16/05/15 8 3) Create the C program Static Library using ar utility: $ ar cr libarith.a addition.o multiplication.o 4) Write c program to use the library libarith.a: Create header.h Create example.c: #include<stdio.h> #include “header.h” Int addition(int a, int b); int main() Int multiplication(int a, intb); { int result; result=addition(1,2); printf(“addition result is : %dn” , result); result=multiplication(3,2); printf(“multiplication result is : %dn”, result);
  • 9. 16/05/15 9 • Compile example.c $ gcc –Wall example.c libarith.a –o example Result: $ ./example addition result is :3 multiplication result is : 6
  • 10. 16/05/15 10 To Command Result List Object Files $ ar t libarith.a addition.o multiplication.o Extract object files from archive $ ar x libarith.a $ ls *.o Addition.o Multiplication.o Add object file into existing archive file $ ar r libarith.a subtraction.o Addition.o Multiplication.o Subtraction.o Delete the specific archive member $ ar d libarith.a addition.o Multiplication.o Subtraction.o
  • 11. 16/05/15 11 1. Create code that has to be added to Shared Library 2. Create a header file 3. Create a shared library 4. Write a program which uses shared library 5. Link the code with shared library 6. Set the environment variable 7. Run the program Steps to Create Shared Library
  • 12. 16/05/15 12 Step 1. shared.c: #include “shared.h” Unsigned int add(unsigned int a, unsigned int b) { Printf(“n Inside add()n”); Return(a+b); } Step 2. Shared.h: #include<stdio.h> extern unsigned int add(unsigned int a, unsigned int b);
  • 13. 16/05/15 13 Step 3. gcc –c –Wall – werror –fPIC shared.c gcc –shared –o libshared.so shared.o Step 4. #include<stdio.h> #include”shared.h” int main(void) { unsigned int a=1; unsigned int b=2; unsigned int result =0; result=add(a,b); printf(“n the result is [%u]n”, result); return 0; }
  • 14. 16/05/15 14 Step 5. gcc –L/home/Desktop/practice/ -wall main.c –o main –lshared Step 6. export LD_LIBRARY_PATH=/home/desktop/practice:$ LD_LIBRARY_PATH Step 7. $ ./main Inside add() The result is [3]
  • 16. 16/05/15 16 Static Library Shared Library Increased memory for each program Contains a record of 1. Name of the symbol 2. Which library is it from Time Consuming Time Efficient Re-linking difficulties Run time linking using Fully Qualified soname Run time Execution is relatively fast Run time Execution is relatively slow Objects of unresolved symbols get copied to the address space Shared library is mapped to address space of program Extension - .a Extensions - .so(.x.x) Difference b/w Static & Shared Library
  • 17. 16/05/15 17 How Static Library Works? File a.o b.o Libx.a Liby.a Object a.o b.o X1.o X2.o Y1.o Y2.o Definitions a1,a2,A3 b1,B2,b3 x11,X12 X21,x22 y11,Y12 y21, Y22 Undefined refernce b2,x12 a3,y22 x23,y12 y11 y21
  • 18. 16/05/15 18 int e=7; int main() { int r = a(); exit(0); } main.c add.c extern int e; int *ep=&e; int x=15; int y; int a() { return *ep+x+y; } How Shared Library Works?
  • 19. 16/05/15 19 Merging .o files into an executable int e = 7 headers system code main() a() int *ep = &e more system code system data int x = 15 .text .data uninitialized data .bss .symtab .debug system code system data .text .data & .bss main()main.o int e = 7 .text .data add.o int *ep = &e a() int x = 15 int y .text .data .bss a() Relocatable object files 0 Executable object files
  • 20. 16/05/15 20 “by Sriee Gowthem Raaj”