Static and Dynamic Libraries Flashcards

1
Q

what is a library

A

library is a collection of reusable code that can be linked to other programs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

c library

A

A C library is a collection of compiled modules, a group of object .o files collected together in a single library file.

All of the non-static global identifiers (variables/functions) in each
module are visible to any other program to which the library is linked. Each compiled object file in the library is compiled from a .c source code module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

static libraries

A

When you link a program to a static library, a copy of the library’s code is added to the resulting executable program

The executable program is permanently associated with the specific version of the static library that you linked it to

to change the version of the library that the program uses is to recompile the entire program and re-link it to the new version of the library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

dynamic libraries

A

also called a shared library

one copy of the compiled library on disk can be shared by any number of different running programs.

the dynamic library’s compiled code is not copied into the executable program.
The program contains only a “reference” to the library

It is only loaded when some function or variable in the library is actually used at run-time.
This is advantageous because a computer need have only one copy of a shared library stored on its hard drive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

dynamic continued

A

The advantage of dynamic libraries is that a program linked to one may dynamically load a different version of the library than the one it was initially linked to. This allows library code to be upgraded, debugged, and improved,

A dynamic library usually has a .so extension (short for shared object) on LINUX

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Linking to a Library

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Building a Static Library

A

ar -r -c -s lib < libname >.a <file1>.o, <file2>.o ... <filen .o></file2></file1>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly