Static libraries

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 linking phase of a program. Simply put, static libraries allow users to link to programs without having to recompile their code, saving compilation time.

Here, I will show you how to create your own static library for your programs.

No hay texto alternativo para esta imagen

To convert all .c files to object files (.o) at once, you can apply this script at the prompt:

No hay texto alternativo para esta imagen
No hay texto alternativo para esta imagen

 Now, you have all the object files you want to add to your library. So to create a library and add those files you have to use this simple script in the directory where all the .o files are:

No hay texto alternativo para esta imagen

Finally, as physical libraries we have to index or order the information we have there. This is good practice because it will make the linking step faster:

No hay texto alternativo para esta imagen

We have now created a static library libmy.a and this allows us to use it by invoking it as part of the linking process when creating an executable program. We can do this easily, you just have to use the flag when you apply the gcc build code:

 ·        -l: library name without prefix and lib extension.

·        -L: specifies the path to the library. We can use -L. to point to the current directory and -L / home / static to point to the / home / static directory.

 Static linking is useful, but it has two main disadvantages:

·        If your library code is updated, you must recompile your program.

·        Each system program that uses that library contains a copy in its executable. This is very inefficient and gets worse if you encounter a bug and have to recompile.

 


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…

  • DINAMIC LIBRARIES.

    Dynamic Libraries are libraries that are linked when executing, the operating system must find them when executing the…

  • ¿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…

Insights from the community

Others also viewed

Explore topics