Sign in

Differences between dynamic libraries vs static libraries

Why use libraries?

int main(void)
{
int x = 5;
int y = 8;
int result; result = sum(x, y);
return (0);
}
int sum(int a, int b)
{
return (a + b);
}int main(void)
{
int x = 5;
int y = 8;
int result; result = sum(x, y);
return (0);
}

How they work

How to create them

$ gcc -c sum.c   // produces a sum.o object file
$ ar -rc libforme.a sum.o
$ nm libforme.a// sample outputsum.o:000000000000002e T sum

How to use them

int main(void)
{
int x = 5;
int y = 8;
int result; result = sum(x, y);
return (0);
}
gcc my_program.c// oops... ///tmp/ccGLAk66.o: In function `main':my_program.c:(.text+0x26): undefined reference to `sum'collect2: error: ld returned 1 exit status
gcc my_program.c -L. -lforme -o my_program

DIFFERENCES

HOW DOES THE SYSTEM FIND THE LIBRARIES?

GCC

NM

LDD

LDCONFIG

RANLIB

AR

XD

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store