Static libraries or How to make easier your life as a programmer 101

Lucia Rodriguez
2 min readMar 4, 2019

Hi again!

Tonight is a weird one: I’m fighting against some checkers for some Holberton projects task and thinking about time and sense of proportion. I usually say that time at Holberton School passes fast and bring loads of tasks, lectures and shared time with people whom you barely know a month ago but you learn to appreciate them as partners in misadventures.

Just kidding. Holberton academic scheme is challenging but it’s not impossible. It’s like a needy but lovely husband.

Tonight’s topic is related with sense of proportion, or I think so: static libraries or the power of “there’s no need to write the same function again and again”.

Programming can be quite simple yet powerful. If you have an appropiate mindset, you can code every single step of your program to make it light and useful, not only on that very executable, but you can reuse it every time you need it. However, even if you have your code clear, can you imagine writing your code down every single time you have to use it? Maybe it’s a short code or maybe you have thousands of lines in it but at the end, writing it again and again is a waste of resources, sometimes.

Static libraries can merge all the pieces of code you’ve written before and produces an all-in-one executable file which you can use for bringing your codes everywhere. It’s really useful.

For Holberton we’ve created our version of some commands like strstr or atoi, and one of our tasks on a recent project was creating our own libraries. I used the following code in order to do so:

Thanks, Terminator!

So, I use this to get a liball.a file,which contains all the functions .c I previously stored in that directory. I ran a gcc command with the -c option to get the object archives (all the .o files) required to create the library.

--

--