Shared (dynamic) Libraries vs. Static Libraries.

What’s is a static library?

gcc -c *.c
ar -rc libholberton.a *.o
ranlib libholberton.a
ar -t libholberton.a
nm libholberton.a
gcc main.c -L. -lholberton -o main

What are Dynamic Libraries in C?

Shared libraries (also called Dynamic libraries) are linked dynamically simply including the address of the library (whereas static linking is a waste of space). Dynamic linking links the libraries at the run-time. Thus, all the functions are in a special place in memory space, and every program can access them, without having multiple copies of them.

How do libraries work?

How to Create a Dynamic Library (Linux)?

First thing you must do is create your C source files containing any functions that will be used and a header file named ‘holberton.h’ that contains the prototypes of these functions.Your library can contain multiple object files.

gcc *.c -c -fPIC
gcc *.o -shared -o
nm -D

Using Dynamic Libraries (Linux):

gcc -Wall -Werror -Wextra -pedantic -L. 0-main.c -lholberton -o len



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