STATIC LIBRARIES

Daniel felipe Escobar chavez
2 min readMar 2, 2021

--

hello friends, this is a blog to prepare to talk about a topic that may be useful for some c programmers so let’s get started.
I will talk about static libraries and their importance in creating functions in c.
WHY?:
I will begin by answering the main question about why use these libraries and it could be said that they are used for convenience and organization because with this you can use the function you want through this library.
To be clearer, a static library is like a record of the functions that we have created and a way to use them whenever we want comfortably.
HOW DOES IT WORK WITH THESE LIBRARIES ?:
It is quite simple as long as you follow the steps well, to handle them at least you must have a function or an instruction that you want to fulfill such as counting numbers from one to 10, then you have to create the library and in the end you only have to execute the function that want from the bookstore.
HOW TO CREATE THEM ?:

  • Well now we go to the most important part of the process. By following these steps they will be able to handle the libraries with ease
    the first thing will be to create a function, what that function does will depend on each person
emacs example.c
  • The next thing will be to pass that file to a .o file using the following command so that the library that we create can store it.
gcc -Wall -pedantic -Werror -Wextra -c *.c

we will do it like this in case there are several functions

  • In the next one, it will be to create the library and put in it all the files that end in .o, the library will be called libh.a
ar -rc libh.a *.o
  • then to check that we did it right we use this command that will show our .o files
ar -t libh.a

this will show the functions you have created

now to make our library run we make use of

ranlib libh

with this everything is ready to use our library
HOW TO USE THEM ?:
to use the library we will create a main.c file to which we will put one of our functions

gcc main.c -L. -lh -o alpha

the -L is the address and the lib is changed to l to shorten the command.
well friends this is all the information I have to share today. I hope it is very useful to someone.
see you later!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response