Static C Libraries

Manuel Enrique Figueroa
2 min readOct 9, 2020

--

Why use static C libararies?

Libraries are faster alternatives to a usual header and functions seperated by files. They make it easier to compile functions since it speeds up the overall linking proccess due to the system not needing to open and close each individual file like it normall would. It is also easier to access accross you system overall creating a larger scope for your functions.

How do they work?

C static libararies work by placing object files for your functions all in one place for the compiler to use during the linking proccess through indexing of each function.

How to create them?

Step 1: create a C file with your function

Step 2: create a header file with you prototype function

Step 3: create a object file using gcc -c file_name.c

Step 4: use the ar rc command to make you library

Once a library is created it appears with the file extension (.a)

How to use them?

In order to use you new library in a function you have to compile a object file of you C program using ( gcc <file_name.o> -l )

Make sure you have your header file included in you program head !

--

--

Manuel Enrique Figueroa
Manuel Enrique Figueroa

Written by Manuel Enrique Figueroa

0 Followers

I am a current student at Holberton school of software engineering aspiring to have a career in full stack software engineering.

No responses yet