Libraries in C programming Language

Victor Hugo Cuartas Ruiz
2 min readFeb 28, 2021

--

If needed to use the code that it has created before, an easy way to use it again without repeating the process is using a library. The library lets you use that code that it has created before and to do reference to them in other program. That call that it makes becomes part of code is creating. That lets not install other files to use.

This is the solution of the problems that present when it is developmenting a very large application, where it is needed to create certain files that make little functions inside. After that, they will be linked.

The static libraries are only used in the link stage inside the compilation process, so after the file has compiled, they won’t be used. Basically, a static library is a file objects set. In the time when the compiler links the object files to generate executable, It searches the symbols mentioned in the program and then uses them in the main code.

When using the program ‘ar’ with the flags rc adding the object files after the name of the library can be created.

In the above example, it can be seen that it’s using the flags ‘rc’. With the flag ‘c’ creates the library if it doesn’t exist. With the flag ‘r’ can be replaced the older objects by the newer objects.

After the library was created, to use it in a program can add the name of the library to the list of objects using the flag ‘l’. As can be seen in the above example.

With that command will create a program through the main.o object file. Neither the prefix ‘lib’ nor the suffix ‘.a’ is being used. In the linker stage of the compilation process are linked

In the last example, can see that the flag -L is used, This flag shows to linker the libraries can look for in the current directory ‘.’ i.e., in the directory where the command has been executed, likewise the standard libraries where they are looked for the compiler.

--

--

No responses yet