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 6084243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:29:54+00:00 2026-05-23T11:29:54+00:00

Can anyone explain me what is the difference between a shared and static library

  • 0

Can anyone explain me what is the difference between a shared and static library in gcc(makefile)

I read that static library is independent code but it increases the size of your exectuable file

But whereas the shared library it links the functions dynamically and it does not increase the size of your executable file

I cannot understand the difference between these two.

Can anyone tell me when i should create a static library and when i should create a shared library.

They say shared library is a position dependent code

What do we mean by position dependent code?

If shared library does not increase the code and if static library increases the code size
then we can just go for shared library right.

But why do we have static library too what is the real use of it.

please help me guys

  • 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-23T11:29:55+00:00Added an answer on May 23, 2026 at 11:29 am

    When you compile code with gcc, it can directly produce object files and a number of object files can be linked together to produce an executable file.

    A static library is simply a collection of object files (usually with an index) which can be used by a linker when it creates an executable.

    The difference between just linking object files together and linking with a static library is that with the library, the linker will only pick the object files from it that are absolutely needed, whereas linking with object files, the linker is forced to take all of the files.

    A dynamic library is different again – very different. It is a collection of object files, but this time its the output of a linking process with all of its internal links already resolved.

    Linking with a dynamic library means that the linker only resolves symbols in the final executable, but adds none of the object code from the library at link time.

    Running an executable linked with dynamic libraries means that at run-time some special software has to ask the operating system to load a specified dynamic library into memory (this is why a dynamic library has to be created by a linker) usually before the program gets to main().

    This executable can be a very small file on disk, but when loaded into memory and after loading dynamic libraries the total memory image can be quite large as the whole of the library will have been loaded in.

    I believe its the case that if several different programs need the same dynamic library, the operating system can use virtual memory for each program to load the library, but this only uses one copy of physical memory – which can be a big saving in some cases.

    If you ship an executable which needs a dynamic library, then you might be lucky and the file might already be on the user’s machine. If not, you would have to install that as well. However, if you find bugs in your library, then just shipping a new version of your dynamic library will fix the bugs.

    An executable built with static libraries comes ready to run, but fixing bugs would involve reshipping the whole executable.

    In Summary:

                   object files  static library  dynamic library
    produced by    compiler      librarian       linker
    exe            large         smaller         smallest
    ram x 1 copy   large         smaller         largest
    ram x n copies large         smaller         smallest
    dep on files   independent   independent     dependant
    upgrade lib    no            no              yes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain insights about the difference between Stack corruption and Static corruption ?
Can anyone point me in the direction of resources that explain the difference between
Can some one explain the conceptual difference between both of them. Read somewhere that
Can anyone explain me what is a difference between these lines of code char
Can anyone explain the difference between Server.MapPath(.) , Server.MapPath(~) , Server.MapPath(@\) and Server.MapPath(/) ?
Can anyone explain the difference between the types mentioned above and some sample usage
Can anyone explain the difference between a fork and a thread?
I want to know the difference Between System.ApplicationException and System.Exception . Can anyone explain
Can anyone please explain to me what is the difference between IEnumerable & IEnumerator
Can anyone explain the difference between the Ruby on Rails console output and the

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.