in Education by
I got some question regarding the shared and static libraries.So let me tell you what i did is, I have created a static library and also a shared library using the gcc commands and the size of libarith.a is 6KB and size of libarith.so is 18KB.Both the libraries contain the same functions. I used one simple function(say add(a,b)) in my make.c file and linked the static library using these gcc command, gcc -L/cygdrive/c/cpros make.c -larith.a # used a static library the size of the exe file is 16.1 KB. Next I used the same function(same add(a,b)) in my make.c file but these time using shared library, like these. gcc make.c /cygdrive/c/cpros/libarith.so #used a shared library unfortunately the size of exe file is 12.1 KB. I wonder how? becuase the size of libarith.so is 18 KB when compared to libarith.a which is just 6 KB.But at the end the exe file generated using the shared library is less compared to static library. Can anyone give me a good reason for that ? If shared libraries consume less memory then why dont we go for shared libraries all the time.Please let me know when do we use shared libraries and when do use static libraries. Yes when I was creating a shared library using -fPIC it gave me a warning position independent code. What does that warning actually mean? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The shared library has a lot of relocation code in it, which is why it is larger than the static library. When you compile an executable with a static library, the static library is included in the executable. When you compile an executable with a shared library, There are many reasons why you would choose static over shared libraries and visa-versa. If you are writing code for an embedded platform, you'd choose static. If your library is used by many other applications and you want to upgrade it without having to recompile (within reason) all the applications, then you'd choose shared. You are also confusing two terms. Memory != Storage. On disk, the shared library may be larger, but when installed you will only have one copy of it. On the other hand, every executable compiled with the static library will have a copy of the static library inside it.

Related questions

0 votes
    Can we place an Excel file in a shared location and use it to develop a report and refresh it in regular intervals?...
asked Oct 30, 2020 in Technology by JackTerrance
0 votes
    Which key do we use to edit the content of more than one sheet at a time ? Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    How to create & use a Shared Library in Jenkins?...
asked Sep 14, 2021 in Technology by JackTerrance
0 votes
    How to create & use a Shared Library in Jenkins?...
asked Jul 17, 2021 in Technology by JackTerrance
0 votes
    How can we visualize more than three dimensions of data in a single chart?...
asked Feb 5, 2021 in Technology by JackTerrance
0 votes
    In a single application, we can spy via more than one spying mode a)False b)True...
asked Dec 11, 2020 in Education by Editorial Staff
0 votes
    I have some ASP.NET web services which all share a common helper class they only need to instantiate one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 31, 2022 in Education by JackTerrance
0 votes
    I have some ASP.NET web services which all share a common helper class they only need to instantiate one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
0 votes
    I have some ASP.NET web services which all share a common helper class they only need to instantiate one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    I have some ASP.NET web services which all share a common helper class they only need to instantiate one ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    On the basis of enthalpy of formation, graphite is more stable than diamond, yet diamond does not change into graphite for years. Why ? Select the correct answer from above options...
asked Jan 4, 2022 in Education by JackTerrance
0 votes
    In some cases, it is found that a large number of colliding molecules have energy more than thereshold value, yet the ... is slow. Why? Select the correct answer from above options...
asked Jan 4, 2022 in Education by JackTerrance
0 votes
    Why are powdered substances more effective adsorbent than their crystalline forms ? Select the correct answer from above options...
asked Jan 4, 2022 in Education by JackTerrance
0 votes
    Why are powdered substances more effective adsorbent than their crystalline forms ? Select the correct answer from above options...
asked Jan 3, 2022 in Education by JackTerrance
0 votes
    Do I need more than the minimum amount of insurance my state requires? Why?...
asked Jan 31, 2021 in Insurance by Editorial Staff
...