0% found this document useful (0 votes)
18 views5 pages

OS Exp-2

The document outlines an experiment conducted at the Sardar Patel Institute of Technology, focusing on creating static and dynamic link libraries for complex number operations such as addition, subtraction, multiplication, and division. It details the programming steps, including the creation of object files, linking them into libraries, and testing the libraries using the linuxld linker. The conclusion emphasizes the successful implementation of both types of libraries and their benefits in terms of modular and reusable code.

Uploaded by

athu120905
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

OS Exp-2

The document outlines an experiment conducted at the Sardar Patel Institute of Technology, focusing on creating static and dynamic link libraries for complex number operations such as addition, subtraction, multiplication, and division. It details the programming steps, including the creation of object files, linking them into libraries, and testing the libraries using the linuxld linker. The conclusion emphasizes the successful implementation of both types of libraries and their benefits in terms of modular and reusable code.

Uploaded by

athu120905
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

BHARATIYA VIDYA BHAVAN’S

SARDAR PATEL INSTITUTE OF TECHNOLOGY


Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

Name Atharv Dipak Thite

UID no. 2023300247

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>

void add(int r1, int i1, int r2, int i2) {


int real = r1 + r2;
int imag = i1 + i2;
if (imag >= 0)
printf("%d + %di\n", real, imag);
else
printf("%d - %di\n", real, -imag);
}

lib_sub.c :
#include <stdio.h>

void sub(int r1, int i1, int r2, int i2) {


int real = r1 - r2;
int imag = i1 - i2;
if (imag >= 0)
printf("%d + %di\n", real, imag);
else
printf("%d - %di\n", real, -imag);
}
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

lib_mul.c :
#include <stdio.h>

void mul(int r1, int i1, int r2, int i2) {


int real = r1 * r2 - i1 * i2;
int imag = r1 * i2 + i1 * r2;
if (imag >= 0)
printf("%d + %di\n", real, imag);
else
printf("%d - %di\n", real, -imag);
}

lib_div.c :
#include <stdio.h>

void div(int r1, int i1, int r2, int i2) {


int denom = r2 * r2 + i2 * i2;
int real = (r1 * r2 + i1 * i2) / denom;
int imag = (i1 * r2 - r1 * i2) / denom;

if (imag >= 0)
printf("%d + %di\n", real, imag);
else
printf("%d - %di\n", real, -imag);
}

Static Linking

Step 1 - Create object files for each of the c programs.

Step 2 - Link object files in lib_calc.a


BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

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

Step 4 - Compile main.c

Step 5 - Execute main.c

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.

You might also like