Libraries In Programing Languages

Functions are blocks of code that perform specific tasks, roughly, we can divide their use in 2, the declaration and the call. The declaration seeks to create and define the function and how it works as indicated in the following examples.

The next step is the call to the function, it consists of using an existing function to perform a task, this call can be made in any section of the code as long as the file containing the requested function is imported.

A library is a collection of functions that are used at the disposal of the programmer in order to facilitate the work. with its use you can avoid the rewriting of code making use of the call of existing functions to perform a task or in other words, not reinventing functions.

Libraries can be created and included in 2 ways and their way of creating them gives them names, static or dynamic. In the case of static libraries in C, these can be created compiling our c files in object files: with the command:

and finally use this command to create the static library:

To make use of the static library you need to include the header of the library in the main program, compile and execute.

In the case of dynamic libraries in C, these can be created compiling our c files in object files: with the command:

and finally use this command to create the dynamic library:

To make use of the dynamic library, it must be added to the environment variable LD_LIBRARY_PATH so that it can be used by any program, and to finish, compile and execute

Once the library is created we can use the following commands to view its content

The biggest difference between these bookstores is the way they work.
The static libraries are added to the main program during compilation, in the linking phase, it means that the program must be compiled together with all the libraries it requires for its correct operation. On the other hand, the dynamic library contains its functions compiled and stored in its own executable to later be linked by other programs at runtime.

The static libraries must be present during the compilation of the main program, this creates a strongly linked relationship between the main program and the library, since the final executable will have everything necessary to function correctly by itself, and this can be an advantage or disadvantage depending on the case, however to modify the library and see the changes reflected in the main program, a recompilation is necessary.

In the case of dynamic libraries, being an external executable to the main program, they must be present during the execution of the program for its correct operation, as it is not part of the compilation but of the execution, the modification of the library does not require a recompilation to see the changes, in addition, its use can be shared by other programs (that is why they are also known as shared libraries), this is not possible with a static library, since for this, each program should have the library included in its executable code

--

--

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