Thread: static lib vs dynamic lib

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    87

    static lib vs dynamic lib

    Is it safe to say we'd use static libraries when a program relies on functionality that rarely changes, such as C++ and STL (standard template library?) despite more space used since static library is linked at build time so becomes part of the final exe?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    static libraries are most useful in programs that need to run on more computers, with fewer dependencies. the STL is almost entirely header files, so to call it static linking is technically accurate, but it doesn't tell the whole story. the C++ standard library - the parts that aren't template based - are usually linked dynamically, because it's possible, and likely, that many programs will use the shared functionality.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Quote Originally Posted by monkey_c_monkey View Post
    Is it safe to say we'd use static libraries when a program relies on functionality that rarely changes, such as C++ and STL (standard template library?) despite more space used since static library is linked at build time so becomes part of the final exe?
    Pretty much what Elkvis said. Generally using a dynamically linked library is a good plan for code that is heavily shared between many programs. For example, C++ libraries, runtime support libraries, etc.. Or your own code, if it's going to be used by lots of different programs.

    I've not thought of it having a 'how often functionality changes' factor. It's true that you can drop in updated dynamic libraries without having to relink your program, but I can't quite think of when that'd be useful. You can't change any interfaces or take advantage of new functions without relinking. But if you had all the interfaces in place you could develop a dynamic library independently I suppose.

    I tend to favour static libraries. These days it's hard to get too freaked out about disk space.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by smokeyangel View Post
    drop in updated dynamic libraries without having to relink your program, but I can't quite think of when that'd be useful.
    automatic updates and bugfixes can easily be accomplished using this method. also, if your program supports a plugin interface, and the plugins are implemented as shared libraries with a common interface, this is extremely useful.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Dynamic libraries can be the source of many bugs (and bloat) since many versions tend to assume a given version of the library and will fail to work with a newer one. This makes one unable to update the library without breaking older applications.
    The solution is usually to deprecate old functions and introduce new ones that new applications can use and leave the old ones for older applications. This causes bloat.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory (Static vs Dynamic)
    By tempster09 in forum C Programming
    Replies: 2
    Last Post: 12-11-2009, 06:39 PM
  2. /MD or /MT? dynamic or static
    By siavoshkc in forum Tech Board
    Replies: 5
    Last Post: 10-02-2006, 04:24 AM
  3. dynamic/static binding
    By faze in forum C++ Programming
    Replies: 7
    Last Post: 07-10-2005, 12:26 PM
  4. static and dynamic
    By chrismiceli in forum C Programming
    Replies: 1
    Last Post: 08-18-2003, 09:19 PM
  5. dynamic or static binding
    By noob2c in forum C++ Programming
    Replies: 1
    Last Post: 08-06-2003, 01:43 PM