How is a "static library" different from a "DLL"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jr

    How is a "static library" different from a "DLL"

    I am working in VC++ so this may be microsoft specific though I don't think
    so. Excuse me if it is.

    Assuming it isn't, can someone generally explain the purpose of having
    both - is it purely a deployment/distribution thing.

    I notice that the static library generates obj files and a Lib file. Could
    someone kindly explain how they relate to one another.

    Thanks very much

    John

    --
    ---
    If you need to reply personally, append "text" to the domain name in my
    email adr.
    Thanks


  • Xenos

    #2
    Re: How is a "static library" different from a "DLL&qu ot;


    "jr" <johnr@tele.co. uk> wrote in message
    news:c7u32e$3mf $1@newsg3.svr.p ol.co.uk...[color=blue]
    > I am working in VC++ so this may be microsoft specific though I don't[/color]
    think[color=blue]
    > so. Excuse me if it is.
    >
    > Assuming it isn't, can someone generally explain the purpose of having
    > both - is it purely a deployment/distribution thing.
    >
    > I notice that the static library generates obj files and a Lib file. Could
    > someone kindly explain how they relate to one another.
    >
    > Thanks very much
    >
    > John
    >
    > --
    > ---
    > If you need to reply personally, append "text" to the domain name in my
    > email adr.
    > Thanks
    >
    >[/color]

    An obj file is generated when a C++ source file (et. al.) is compiled. It
    is linked with other (or possibly none) obj files to form an executable. A
    lib file is an archive (equilivant to a unix *.a file). It contains 1 or
    more objs. Your linker will search a lib file for undefined symbols. If it
    finds any symbols that it needs in the archive, it will link in the
    object(s) that contain them. A DLL is a dynamically linked library (similar
    to a unix shared library or *.so file). It is loaded during runtime by
    programs that need it and is shared by other running programs that also need
    it.

    Simplicistic, but good enough I guess.


    Comment

    • jr

      #3
      Re: How is a &quot;static library&quot; different from a &quot;DLL&qu ot;

      Thanks
      Great help.

      "Xenos" <dont.spam.me@s pamhate.com> wrote in message
      news:c7u3ua$7sr 2@cui1.lmms.lmc o.com...[color=blue]
      >
      > "jr" <johnr@tele.co. uk> wrote in message
      > news:c7u32e$3mf $1@newsg3.svr.p ol.co.uk...[color=green]
      > > I am working in VC++ so this may be microsoft specific though I don't[/color]
      > think[color=green]
      > > so. Excuse me if it is.
      > >
      > > Assuming it isn't, can someone generally explain the purpose of having
      > > both - is it purely a deployment/distribution thing.
      > >
      > > I notice that the static library generates obj files and a Lib file.[/color][/color]
      Could[color=blue][color=green]
      > > someone kindly explain how they relate to one another.
      > >
      > > Thanks very much
      > >
      > > John
      > >
      > > --
      > > ---
      > > If you need to reply personally, append "text" to the domain name in my
      > > email adr.
      > > Thanks
      > >
      > >[/color]
      >
      > An obj file is generated when a C++ source file (et. al.) is compiled. It
      > is linked with other (or possibly none) obj files to form an executable.[/color]
      A[color=blue]
      > lib file is an archive (equilivant to a unix *.a file). It contains 1 or
      > more objs. Your linker will search a lib file for undefined symbols. If[/color]
      it[color=blue]
      > finds any symbols that it needs in the archive, it will link in the
      > object(s) that contain them. A DLL is a dynamically linked library[/color]
      (similar[color=blue]
      > to a unix shared library or *.so file). It is loaded during runtime by
      > programs that need it and is shared by other running programs that also[/color]
      need[color=blue]
      > it.
      >
      > Simplicistic, but good enough I guess.
      >
      >[/color]


      Comment

      • Dave Townsend

        #4
        Re: How is a &quot;static library&quot; different from a &quot;DLL&qu ot;

        John,

        DLL = dynamic link library. This means that the library code is not
        actually
        linked into your executable, but remains in a separate file and is loaded
        either
        when you start the executable, or can actually be loaded on-request by the
        program.

        DLLs are somewhere between the .lib file and the executable on the
        evolutionary path,
        DLLs are actually linked , .lib files are merely repositories for .obj files
        and other .libs, just
        packaged into a more convenient medium. Symbols in DLLs have to be
        partially resolved,
        that is to say if you call foo() it better be in the DLL or in another DLL
        which the first
        DLL refers to.

        ..lib files are linked into the executable code. The code in the .lib file
        "becomes" part of
        the executable. They are really just collections of .obj's

        When you create a DLL, a .lib is also created. This is actually a "proxy"
        which I will explain.

        The DLL's .lib file will contain stubs or dummies for each of the functions
        you export from the dll.
        The .lib is linked into your executable as a place holder to call functions
        in the DLL.
        When you make a call to a function foobar(), the .lib stub foobar() will
        actually execute the
        function in the dll for you. This is all taken care of under the hood for
        you when you use DLLs.


        The advantages of DLLs are:

        1. you can update the DLL without relinking the executable or
        redistribution the executable.
        ( provided you don't add new functions or changes interfaces )
        2. One DLL can be shared amongst a number of different executables so you
        save on disk storage.
        In reality, there are normally several copies of a DLL because
        executables often require an
        exact version of a dll to work correctly.
        3. Since DLLs can be loaded on-demand, the start up time of the exectuable,
        its memory footprint, etc
        can be minimized to the essential functionality. Many of microsoft's
        products make heavy use of
        this feature through another technology called COM, which provides a
        streamlined means to
        execute functions in a dynamically loaded DLL.

        Disadvantages:
        1. DLL HELL - you have multiple versions of DLL which are all incompatible
        with each other.
        2. DLL code may be slightly slower in execution speed because of the code
        has be to
        relocatable at run-time and certain optimizations cannot be performed.
        3. You have to ship DLLS along with the executable, so its a bit more
        complex in deployment.
        You also have to be sure your executable is picking up the correct
        versions of DLLs on the
        system.
        4. There are some arcane rules for exporting functions from a DLL, just
        adding the code is
        not enough. However, these rules are fairly mechanical, and can be
        mastered after a few
        encounters.

        Hope that helps.

        dave

        "jr" <johnr@tele.co. uk> wrote in message
        news:c7u32e$3mf $1@newsg3.svr.p ol.co.uk...[color=blue]
        > I am working in VC++ so this may be microsoft specific though I don't[/color]
        think[color=blue]
        > so. Excuse me if it is.
        >
        > Assuming it isn't, can someone generally explain the purpose of having
        > both - is it purely a deployment/distribution thing.
        >
        > I notice that the static library generates obj files and a Lib file. Could
        > someone kindly explain how they relate to one another.
        >
        > Thanks very much
        >
        > John
        >
        > --
        > ---
        > If you need to reply personally, append "text" to the domain name in my
        > email adr.
        > Thanks
        >
        >[/color]


        Comment

        • David White

          #5
          Re: How is a &quot;static library&quot; different from a &quot;DLL&qu ot;

          "Dave Townsend" <datownsend@com cast.net> wrote in message
          news:gO2dnY87MP 2cPT_dRVn-sw@comcast.com. ..[color=blue]
          > DLL = dynamic link library. This means that the library code is not
          > actually
          > linked into your executable, but remains in a separate file and is loaded
          > either
          > when you start the executable, or can actually be loaded on-request by the
          > program.[/color]

          [snip]

          It should be added that the OP's suspicion that his question might be
          MS-specific, or at least platform-specific, was correct. None of this stuff
          has anything to do with the C++ language.

          DW



          Comment

          Working...