DINAMIC LIBRARIES.

DINAMIC LIBRARIES.


Dynamic Libraries are libraries that are linked when executing, the operating system must find them when executing the program. If an application installed successfully, the operating system should have no problem finding it. In Windows they have the extension. On Linux they have the extension .so (usually in / usr / lib or / usr / local / lib

¿ Why Using Libraries In General?

Be bein able to include these libraries with definitions of different functionalities we can save a lot of things, imagine for example that every time we need to read from the keyboard, we must then create a function that dowes it (something really complex), since we can have the libraries in C, we will be able to make use of great variety of functions that will make our lives easier and will increase the modularity of our codes.

No hay texto alternativo para esta imagen

Difference Between Static Library And Dinamic Library.

dynamic libraries consist of separate files containing separate pieces of object code. These files are dynamically linked together to form a single piece of object code. Furthermore, dynamic libraries contain extra information that the operating system will need to link the library to other programs.

The implication of this is that memory is conserved while using dynamic libraries since each application or program can access the dynamic library without needing an individual copy, as would be the case, if we were using static libraries. Although dynamic libraries afford the ability to alter source code without recompiling the entire program, static libraries’ execution speed at run-time is faster because the object code for the functions within the library are already in the executable file. As a result, multiple calls to functions are handled more efficiently than when using dynamic libraries.

Create a Dinamic Library (Linux)

To create a dynamic library in Linux, simply type the following command: gcc *.c -c -fPIC and hit return. This command essentially generates one object file .o for each source file .c . The -fPIC flag ensures that the code is position-independent. This means it wouldn’t matter where the computer loads the code into memory. The -c options just ensures that each .o file isn’t linked yet.

Thats look at linux terminal step 1.

The second step is enter the following command: gcc *.o -shared -o libdynamic.so The wildcard * tells the compiler to compile all the .o files into a dynamic library which is specified by the -shared flag. The naming convention for dynamic libraries is such that each shared library name must start with lib and end with .so.

Thats looks at the linux terminal step 2.

Using Dynamic Libraries (Linux)

The point of creating a dynamic library is to use it with other programs. You can compile your code as follows:

No hay texto alternativo para esta imagen

In the above command it is worth noting that your source code, test_code.cin this case, needs to be listed before the -l flag. The expression, -lcombined with holberton tells the compiler to look for a dynamic library called libholberton.so, while the -L flag tells the compiler to look in the current directory for the library file. This is why it is important to use the standard format for naming that I described earlier. For instance if test_code.c was the following:

No hay texto alternativo para esta imagen

Typing and executing gcc -L test_code.c -lholberton -o test_code would generate an executable file called test_code. In order to accomplish this, the compiler looks through the library that is specified with the -l flag for the _puts function object code. Executing test_code like so: ./test_code would give us the following output: Hello World!.

To view or add a comment, sign in

More articles by Christian Sánchez

  • Prototype: make your solution real enough

    Introduction: In a previous article, we discuss the UX research which was the 1st part of a design project to improve a…

  • Full Stack web developer: the IT profile of the moment.

    The technological world is growing and changing more and more, and especially the world of development, where this…

  • What happens when you type google.com in your browser and press Enter!!!

    We use internet all the time for all sorts of purposes, and it has become like a second nature to browse all day. So…

  • INTERNET OF THINGS IoT

    ¿What is the Internet of Things IoT? The Internet of Things, or IoT, refers to the billions of physical devices around…

  • Recursion

    ¿What is Recursion? In computer science, Recursion is a function that calls itself until a basic condition is met. For…

    2 Comments
  • Mutable, Immutable... Everything Is Object!

    Python is an object-oriented programming language, so everything in python is an object. Every object has some data…

  • Class And Instance Attributes In Python

    As an object oriented programming language, Python provides two scopes for attributes: class attributes and instance…

  • ¿What happens when ls -l is written to the shell?

    Initially we must know what an environment variable is. In Linux environment variables are place holders for…

  • Static libraries

    A static library is an object file that contains several object files, which can also be used as a single entity in a…

Insights from the community

Others also viewed

Explore topics