OS Exp-2
OS Exp-2
Class D
Batch B
Experiment No. 2
Aim : Write a program for creating static and dynamic link library for complex
number operations (addition, subtraction, multiplication, division) and then
test this library using linuxld linker.
Programs
lib_add.c :
#include <stdio.h>
lib_sub.c :
#include <stdio.h>
lib_mul.c :
#include <stdio.h>
lib_div.c :
#include <stdio.h>
if (imag >= 0)
printf("%d + %di\n", real, imag);
else
printf("%d - %di\n", real, -imag);
}
Static Linking
Step 3 - Write header file calc.h where functions are declared and main function main.c.
calc.h
main.c
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
RESULT :
Dynamic Linking
Step 1 -
Step 2 -
Step 3 -
Step 4 -
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering
Step 5 -
Step 6 -
Step 7 -
RESULT :
CONCLUSION : In this experiment, we successfully created both static and dynamic link
libraries for performing complex number operations, including addition,
subtraction, multiplication, and division.
Static Library(.a file) is type of library is linked at compile time, meaning
that the necessary functions from the library are copied into the final
executable.
Dynamic Library(.so file) is type of library is linked at runtime, allowing
the executable to remain smaller.
We then tested these libraries using the linuxld linker to ensure proper
functionality. This demonstrated the process of compiling, linking, and
using shared and static libraries in a Linux environment, highlighting the
advantages of modular and reusable code.