Question: Q 2 . ( a ) What is the difference between a statically linked library ( or archive ) and a dynamically linked library (
Qa What is the difference between a statically linked library or archive and
a dynamically linked library or shared object State the advantages and
disadvantages of each. For each type of library, give an example where it would
be the preferred choice.
Scrutinise the code for a small library given in Figure Q Throughout this question,
line numbers are included only for ease of reference and do not constitute part of
the program.
b What would happen if a source file accidentally included the header file twice?
Suggest and enhancement to overcome this problem.
The following small program is written which uses this library:
#include
#include "apse.h
int main
One one;
Counter coneget;
std::cout cget cget std::endl;
return ;
Object files are produced from the source files, and a shared library is created using
the command
gfPIC shared one.o counter.o o libapse.so
The main program called try is then linked using the command
go try main.o Llapse
c Why is the compiler option fPIC necessary when building the shared library?
d What is the function of the L option in building the program?
e Running the program with try produces the message
try: error while loading shared libraries: libapse.so: cannot
open shared object file: No such file or directory.
However, the file libapse.so exists in the build directory. What is the remedy
for this?
Page of OVER
File: apse.h
struct One
int getvoid;
;
class Counter
public:
Counterint start;
int getvoid;
private:
int i;
;
File: apsecxx
#include "apse.h
int One::getvoid return ; ;
File apsecxx
#include "apse.h
Counter::Counterint start : i start
int Counter::getvoid return i;
Figure Q: Source code for the apse library
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
