Entradas

STATIC LIBRARIES VS DYNAMIC LIBRARIES

Imagen
As we make computer programs, we realize that some parts of the code are used in many of them. For example, we can have several programs that use complex numbers and the functions of addition, subtraction, etc. are common. It is also possible, for example, that we like to play games, and we realize that we are repeating the code over and over again to move an image (a little Martian or Lara Croft) across the screen. It would be great to be able to measure those functions in a separate directory from the concrete programs and have them already compiled, so that we can use them whenever we want. The huge advantages of this are:  - Not having to rewrite the code (or copy-paste).  - We will save the time of compiling each time that code that is already compiled. In addition, we already know that while we make a program, we test and correct, it is necessary to compile between many and "more many" times.  - The already compiled code will be tested and will be reliable. Not the ...

STATIC LIBRARIES IN C

Imagen
What is a library and what is it good for? A library is a collection of code routines (functions, classes, variables, and so on) that can be called upon when building our program, so instead of writing it ourselves, we can go and get it from something that has already been written and optimized. That is where the idea behind libraries comes from. We are reusing blocks of codes that have come from somewhere else. What is a static library and how does it work? A static library is a file containing a collection of object files (*.o) that are linked into the program during the linking phase of compilation and are not relevant during runtime. As shown in the diagram above, when a program is compiled, the compiler generates an object file from a source file. After generating the object file, the compiler also invokes the Linker. The role of the linker, in this case, is to copy the code of the library to our object file. Basically, static libraries are just a collection of object files that a...

The steps of compilation

Imagen
In this article we are going to introduce the complete compilation process in detail, from the moment we write a file in source code, until we obtain an executable binary, in C language. What is compilation in C language? The compilation process is to convert one or more source code files into executable binary code for a specific hardware / software architecture. This process involves several stages, which we are going to study below. but first, let's define "Source Code" and "Binary Code": Source code is the program that we as programmers write, the plain text that "tells" the computer how to do things. On the other hand, executable binary code, in general for any compiled language, and in particular for C language, is binary code (not text), which in turn can be executed on the computer. I clarify this, because one of the intermediate products of the compilation process is the object code, which although it is binary, cannot be executed and must con...