WHAT IS A LIBRARY AND STATIC LIBRARIES (C language)

WHAT IS A LIBRARY

A library in programming is a collection of pre-compiled resources, used by computers programs, such as functions, classes, configuration data, documentation and so on.

What is a Static Library

A static library is a collection of objects files that are linked into the program during LINKING phase of compilation. (Not important during run time); So only the program’s executable file is need it in order to run the program.

What is a share or dynamic library

A shared library or shared object is a file that is intended to be shared by executable files and further shared object files. Modules used by a program are loaded from individual shared objects into memory at load time or runtime, rather than being copied by a linker when it creates a single monolithic executable file for the program.

So How compilation Works:

A dynamic library is linked into the program in two stages

  1. During run time: When the program is started the Dynamic loader checks out the libraries that were shared with the program, loads them to memory and engage them in a copy in memory

How to create the static Library

First, convert all source code into object files:

$ gcc -c <source code example: *.c>
ar -rc libName.a objectFile1.o objectFile2.o objectFiles3.o
Example to create a static library Call holbertonschool.a

Ranlinb

A useful command to Up-date the index the compiler

$ ranlib libholbertonschool.a
$ gcc main.c -L. -lholbertonschool -o alpha