DIFFERENCES BETWEEN STATIC AND DYNAMIC LIBRARIES

Giovanny Andres Ortegon Espitia
3 min readSep 17, 2019

--

source: http://scitechconnect.elsevier.com/c-libraries/

To create an executable of our code is necessary, the first step is compile, in this process generate three important phases.

  1. Preprocess
  2. Compile
  3. Linker

In this section, we talk about linker and how to work with the libraries. it is file contain a number of function or subroutines. In linker time it check each function to resolve any reference and when the program do a called of this function it can be used.

STATIC LIBRARY

It is a collection of objects files and inserted into the executable file. So, only the executable file is necessary to run the program in everywhere. however, increment its size.

CREATE A STATIC LIBRARY

  1. Create a header file with all functions
header file with fucntion
each file.c with a function
add function in add.c

2. Create a object file of each function

files .o are object files

3. Create static library

some times is necessary indexed when we add new function to header file

and comeback to step 3 and the argument -r replace existing or insert new file(s) into the archive.

4. Finally create an execute file

generate an execute file

important points about static libraries:

  1. Are not relevant during run time
  2. each process is a copy of the code anda data
  3. Are connected at compile time
  4. to create static library do not need to create a new executable

DYNAMIC LIBRARIES

It library are not into executing file so, is necessary to execute with the library. The format of Shared file or dynamic file is “.so”. Is is created of the same way that the static file.

  1. REPEAT STEP (ONE) OF STATIC LIBRARY
  2. Create an file .so
create .so file

3. Apply compile the program to create execute and apply ldd (List Dynamic Dependencies) is a UNIX utility that prints the shared libraries required by each program or shared library specified on the command line. if library is not , it need to be add to environment variable.

important points about static libraries:

  1. is into the program
  2. need create a new executable
  3. it is only code shared, data is specific to each process
  4. it need to add to environment variable

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