Dynamic Libaries and you: a short story.

Quite the dynamic.

What is a dynamic library?

A dynamic library is a way of combining functions into a shared library in a manner that they are not included within a programs executable and are instead only accessed while it is executed. This allows programs to be shrunken down due to the amount of storage that can be saved with this method. Dynamic libraries also have the advantage that they can be altered without having to be recompiled. This is because dynamic libraries store individual object code that are then linked together to form a single dynamic library.

How to create a Dynamic Library in Linux

gcc *.c -c -fPICgcc *.o -shared -o liball.soexport LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH

These are the 3 commands needed to create a functional Dynamic Library

The first command compiles all our .c files into object files (-c flag) suitable for dynamic linking (-fPIC flag).
Next we compile all our generated object files into a dynamic library (-shared flag) and then we export the compilation into our library file (-o flag followed by lib[all].so).
Once that is done, we need to give our library its path by changing the environmental variable $LD_LIBRARY_PATH.



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