Dynamic libraries in C

Img 1: Static and dynamic libraries in C
img2 : How libraries work
  1. Convert all source code you want to save as a library, into object files:
gcc -c *.c
ar -rc libholberton.a *.o
gcc main.c -L. -lholberton -o main

Dynamic libraries:

gcc -fPIC -c *.c
Img 3: Writing gcc -fPIC -c *.c
gcc *.o -shared -o libholberton.so
Img 4: writing gcc *.o -shared -o libholberton.so
gcc 0-main.c -L. -lholberton -o len
Img 5: main function
Img 6: compiling and creating our dynamic library
  • nm: we used nm command when we need to find out what functions a library has, as we can see in the image
Img 7: writind nm command
  • LD_LIBRARY_PATH and ldd: LD_LIBRARY_PATH. It’s an environment variable, and contains a set of directories where libraries should be searched for first, before the standard set of directories. It is usefull in this case for Configure the loader where to find the shared library. and ldd is a command we used to list the dependencies of a library. The env variable and the command has to be use like you can see in the next image:
Img 8: writing env varaible and ldd command.
Img 9: graphical diferences between static and dynamic libraries

Static Libraries:

Dynamic Libraries:

Hi I am a financial engineer, and a software development student in Holberton School!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Evangelicalism in America is nearing extinction due to the movement’s devotion to politics at the…

The path to Organization Metrics collection

5+1 Reasons Why You Need to Go to REcon

Vicert @ Coding Serbia 2014, Novi Sad — Part I

Design Development and the WYSIWYG Trap, Part 2: Construction and design development

Development Update: The Bridge is Out!

How to find Equivalent Resistance in circuits

Worldwide Webb Metaverse

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
Valentina Gómez A.

Valentina Gómez A.

Hi I am a financial engineer, and a software development student in Holberton School!

More from Medium

C# — Path library inconsistency across platforms

C Static Libraries

A Byte of Coding Issue #208

Speeding up Compliance for C++ Applications