LET'S TALK ABOUT C - Static libraries

LET'S TALK ABOUT C - Static libraries

A static library is an archive file containing object files that remain static until the program is recompiled.

Why do we use libraries?

  • Using a static library only one object file needs to be pulled in during the linking phase. The benefit is that the functions and other symbols loaded into it are indexed and linking a program whose objects files are ordered in libraries is faster than linking files separate on the disk.


How to create them?

No hay texto alternativo para esta imagen


  • Include all function prototypes of .c files into the header file
  • Compile .c files with gcc -c command
  • Create an archive file (static library) with files .o and the command used is ar -rc filename *.o ( "ar" creating and mantaining libraries, "-r" replace or add files, "-c" create a new file and "*.o" is the selection of all object files.


How to use them?

No hay texto alternativo para esta imagen

  • "gcc" command to compile C files, "-L" tell the linker that the libraries be found in the current directory, "-l" links the C file with the library file, "example" name of the static library, "-o" change the name of the executable file.

I hope i could have helped you understand a little about Static libraries.
Stay tuned!
Danielle Serafim.        
Alejandro Senges

Senior Software Developer in Test

3y

Excellent description of the process.

To view or add a comment, sign in

More articles by Danielle Serafim

Insights from the community

Others also viewed

Explore topics