Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6125003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:11:52+00:00 2026-05-23T16:11:52+00:00

I got some question regarding the shared and static libraries.So let me tell you

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:11:53+00:00Added an answer on May 23, 2026 at 4:11 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

got a question regarding serializing classes that I've defined. I have some classes like
(I asked this question in another way , and got some interesting responses but
I got a question regarding content types and their IDs and how to use
Got a (hopefully small) question regarding SVN and checking out repos. Basically I see
I got a question regarding my MySQL-database and would like to get input on
I ve got a question regarding jBPM. In one of our projects I developed
got a question regarding printing out the 128 first characters from the ascii table.
I got a question regarding C++ Object & Javascript Object life cycle mis-synchronization and
I got into another philosophical question regarding Java. It's about the following scenario: You
I've been messing with Win32 API for abit, and I've got a question regarding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.