Differences between Static and Dynamic Libraries in C

source unsplash.com

Why using libraries in general?

How do they work?

#ifndef _H_NAME
....
....
#endif

How to create a Static Library (Linux only)?

$ ar -rc libname.a *.o

How to use them (Linux only)?

$ gcc -llibname -L 0-main.c -o exec_name

How to create a Shared Library (Linux only)?

$ gcc -fPIC -Wall -pedantic -Werror -Wextra -c *.c
$ gcc -shared -o liball.so *.o
$ export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH

How to use them (Linux only)?

$ gcc -Wall -pedantic -Werror -Wextra -L. 0-main.c -lall -o exec_name

What are the differences between Static and Dynamic libraries?

source unsplash.com
source unsplash.com

What are the advantages and drawbacks of each of them?

Advantages of Static Libraries:

Drawbacks of Static Libraries:

Advantages of Shared Libraries:

Drawbacks of Shared Libraries:

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