Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DLL and Static Library Doubt

DLL and Static Library Doubt

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearningworkspace
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Richard Lewis
    wrote on last edited by
    #1

    Consider the following background information: a) I have a static library, say A.lib b) I create a DLL, say D.dll, in which I write functions that require me to link the dll with A.lib c) I ship my dll i.e. D.dll Now comes my doubt: Do I need to ship the static library (A.lib) also along with the DLL? (I observed that when I use the dll in developing an application, the compiler gives me LNK2001 errors for all functions in the static library A.lib. Of course, all LNK2001 errors disappear if I include A.lib in the application workspace. (But that's not the idea, I guess)) Any help will be greatly appreciated.:( Richard

    T R I 3 Replies Last reply
    0
    • R Richard Lewis

      Consider the following background information: a) I have a static library, say A.lib b) I create a DLL, say D.dll, in which I write functions that require me to link the dll with A.lib c) I ship my dll i.e. D.dll Now comes my doubt: Do I need to ship the static library (A.lib) also along with the DLL? (I observed that when I use the dll in developing an application, the compiler gives me LNK2001 errors for all functions in the static library A.lib. Of course, all LNK2001 errors disappear if I include A.lib in the application workspace. (But that's not the idea, I guess)) Any help will be greatly appreciated.:( Richard

      T Offline
      T Offline
      Toni78
      wrote on last edited by
      #2

      richiehere wrote: Do I need to ship the static library (A.lib) also along with the DLL? A.lib is required by the linker, so the users don't need it, and the application that you are distributing requires only the DLL file. Therefore, the answer is no, you don't need to ship the static library. However, if you are distributing only your DLL (which is required by another programmer to develop his/her own code which places function calls to your DLL) then you need to distribute A.lib and A.h as well. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

      R I 2 Replies Last reply
      0
      • T Toni78

        richiehere wrote: Do I need to ship the static library (A.lib) also along with the DLL? A.lib is required by the linker, so the users don't need it, and the application that you are distributing requires only the DLL file. Therefore, the answer is no, you don't need to ship the static library. However, if you are distributing only your DLL (which is required by another programmer to develop his/her own code which places function calls to your DLL) then you need to distribute A.lib and A.h as well. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

        R Offline
        R Offline
        Richard Lewis
        wrote on last edited by
        #3

        Thanks for the reply. I was quite aware that while shipping the 'exe', I dont need to ship the lib file. My specific query was regarding shipping of the static library while shipping the dll. I thought the linker (while creating the dll) would automatically extract out the 'code' from the static library and insert it into the dll code. Therefore, not requiring the lib to be shipped alongwith the dll! Please help.:((

        T 2 Replies Last reply
        0
        • R Richard Lewis

          Thanks for the reply. I was quite aware that while shipping the 'exe', I dont need to ship the lib file. My specific query was regarding shipping of the static library while shipping the dll. I thought the linker (while creating the dll) would automatically extract out the 'code' from the static library and insert it into the dll code. Therefore, not requiring the lib to be shipped alongwith the dll! Please help.:((

          T Offline
          T Offline
          Toni78
          wrote on last edited by
          #4

          Don't get upset richiehere.:) In the previous post I mentioned the fact that if ship your dll only, then you need to send your lib and header file as well. Yes, the linker inserts the code into the dll but the dll is used by the application. For a developer it is necessary to know the functions and the parameters to these functions. That's why the header file needs to be shipped. On the other hand, the linker needs to know where to get the code (or resolve external dependencies) so that's why you need the lib file. But, you can also load the functions from a dll by calling LoadLibrary. In that case the lib file is not required. Having the lib file is more convinient. I don't understand why you won't ship your lib file, but it is up to you to decide what you want to do. If I had a choice I would prefer to get my hands on the lib file instead of calling LoadLibrary. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

          1 Reply Last reply
          0
          • R Richard Lewis

            Thanks for the reply. I was quite aware that while shipping the 'exe', I dont need to ship the lib file. My specific query was regarding shipping of the static library while shipping the dll. I thought the linker (while creating the dll) would automatically extract out the 'code' from the static library and insert it into the dll code. Therefore, not requiring the lib to be shipped alongwith the dll! Please help.:((

            T Offline
            T Offline
            Toni78
            wrote on last edited by
            #5

            Okay, maybe this might help you a little bit more. I just got it from MSDN. "Types of Dynamic Linking There are two methods for calling a function in a DLL: In load-time dynamic linking, a module makes explicit calls to exported DLL functions as if they were local functions. This requires you to link the module with the import library for the DLL that contains the functions. An import library supplies the system with the information needed to load the DLL and locate the exported DLL functions when the application is loaded. In run-time dynamic linking, a module uses the LoadLibrary or LoadLibraryEx function to load the DLL at run time. After the DLL is loaded, the module calls the GetProcAddress function to get the addresses of the exported DLL functions. The module calls the exported DLL functions using the function pointers returned by GetProcAddress. This eliminates the need for an import library." // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

            1 Reply Last reply
            0
            • T Toni78

              richiehere wrote: Do I need to ship the static library (A.lib) also along with the DLL? A.lib is required by the linker, so the users don't need it, and the application that you are distributing requires only the DLL file. Therefore, the answer is no, you don't need to ship the static library. However, if you are distributing only your DLL (which is required by another programmer to develop his/her own code which places function calls to your DLL) then you need to distribute A.lib and A.h as well. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

              I Offline
              I Offline
              Iain Clarke Warrior Programmer
              wrote on last edited by
              #6

              I think you've has got the wrong end of the stick, if I understand his problem correctly. A.lib is a static library used BY B.dll, and is therefore now "built-in" to the DLL. It is not the LIB file created as a consequence of creating the DLL. So he does not need to distribute A.lib under any circumstance. Unless an end user wanted to use the static library themselves, but that would be independent of any reliance on B.DLL. You are right that he would need to distribute B.LIB along with B.DLL if he wanted an end user to link to the DLL, but that is (I believe) a different question. Iain.

              T R 2 Replies Last reply
              0
              • R Richard Lewis

                Consider the following background information: a) I have a static library, say A.lib b) I create a DLL, say D.dll, in which I write functions that require me to link the dll with A.lib c) I ship my dll i.e. D.dll Now comes my doubt: Do I need to ship the static library (A.lib) also along with the DLL? (I observed that when I use the dll in developing an application, the compiler gives me LNK2001 errors for all functions in the static library A.lib. Of course, all LNK2001 errors disappear if I include A.lib in the application workspace. (But that's not the idea, I guess)) Any help will be greatly appreciated.:( Richard

                R Offline
                R Offline
                Ryan Binns
                wrote on last edited by
                #7

                No, you don't need to distribute A.lib. The library is needed by the linker to work out how to implement the calls to functions inside the DLL. It is not needed to use D.dll, and therefore doesn't need to be distributed. Hope this helps,

                Ryan

                "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                T 1 Reply Last reply
                0
                • I Iain Clarke Warrior Programmer

                  I think you've has got the wrong end of the stick, if I understand his problem correctly. A.lib is a static library used BY B.dll, and is therefore now "built-in" to the DLL. It is not the LIB file created as a consequence of creating the DLL. So he does not need to distribute A.lib under any circumstance. Unless an end user wanted to use the static library themselves, but that would be independent of any reliance on B.DLL. You are right that he would need to distribute B.LIB along with B.DLL if he wanted an end user to link to the DLL, but that is (I believe) a different question. Iain.

                  T Offline
                  T Offline
                  Toni78
                  wrote on last edited by
                  #8

                  Iain Clarke wrote: You are right that he would need to distribute B.LIB along with B.DLL if he wanted an end user to link to the DLL, but that is (I believe) a different question. I covered both cases since I wasn't very sure about his question. :) // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

                  1 Reply Last reply
                  0
                  • R Ryan Binns

                    No, you don't need to distribute A.lib. The library is needed by the linker to work out how to implement the calls to functions inside the DLL. It is not needed to use D.dll, and therefore doesn't need to be distributed. Hope this helps,

                    Ryan

                    "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                    T Offline
                    T Offline
                    Toni78
                    wrote on last edited by
                    #9

                    This is what richiehere wrote: "I was quite aware that while shipping the 'exe', I dont need to ship the lib file. My specific query was regarding shipping of the static library while shipping the dll." Therefore, I told him that the library file is needed by the linker, but a developer can also use LoadLibrary (as you know, little bit more work is required). :) // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

                    R 1 Reply Last reply
                    0
                    • R Richard Lewis

                      Consider the following background information: a) I have a static library, say A.lib b) I create a DLL, say D.dll, in which I write functions that require me to link the dll with A.lib c) I ship my dll i.e. D.dll Now comes my doubt: Do I need to ship the static library (A.lib) also along with the DLL? (I observed that when I use the dll in developing an application, the compiler gives me LNK2001 errors for all functions in the static library A.lib. Of course, all LNK2001 errors disappear if I include A.lib in the application workspace. (But that's not the idea, I guess)) Any help will be greatly appreciated.:( Richard

                      I Offline
                      I Offline
                      Iain Clarke Warrior Programmer
                      wrote on last edited by
                      #10

                      I've posted a reply to Toni78 which you should read[^]. Iain.

                      1 Reply Last reply
                      0
                      • T Toni78

                        This is what richiehere wrote: "I was quite aware that while shipping the 'exe', I dont need to ship the lib file. My specific query was regarding shipping of the static library while shipping the dll." Therefore, I told him that the library file is needed by the linker, but a developer can also use LoadLibrary (as you know, little bit more work is required). :) // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

                        R Offline
                        R Offline
                        Ryan Binns
                        wrote on last edited by
                        #11

                        Aaah yes, but was he shipping the library so that other developers could use it, or was it part of his application that he didn't want other people to use? ;) He didn't state this in the question. The most common situation these days is to ship a proprietary DLL as part of an application, so this is what I answered :). Your reply is perfectly valid though :)

                        Ryan

                        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                        1 Reply Last reply
                        0
                        • I Iain Clarke Warrior Programmer

                          I think you've has got the wrong end of the stick, if I understand his problem correctly. A.lib is a static library used BY B.dll, and is therefore now "built-in" to the DLL. It is not the LIB file created as a consequence of creating the DLL. So he does not need to distribute A.lib under any circumstance. Unless an end user wanted to use the static library themselves, but that would be independent of any reliance on B.DLL. You are right that he would need to distribute B.LIB along with B.DLL if he wanted an end user to link to the DLL, but that is (I believe) a different question. Iain.

                          R Offline
                          R Offline
                          Richard Lewis
                          wrote on last edited by
                          #12

                          First of all, thanks for all the 'activity' being generated on this thread! Well I agree with you Ian, that is exactly my understanding. (the understanding that A.lib **need not**be shipped when shipping B.dll. But thats not the way it is working out currently. I have done exactly that. I am conscious of the fact that the size of the dll (B.dll) swells when I statically link A.lib with it. However, when using it in an application, the MSVC compiler generates LNK2001 errors (symbol not found) for all of the functions in the static library!! (I guess you might be skeptic of some settings in my compiler; but trust me it is plain code!) Thanks for help again. (Btw,please respond to this question):confused:

                          I 1 Reply Last reply
                          0
                          • R Richard Lewis

                            First of all, thanks for all the 'activity' being generated on this thread! Well I agree with you Ian, that is exactly my understanding. (the understanding that A.lib **need not**be shipped when shipping B.dll. But thats not the way it is working out currently. I have done exactly that. I am conscious of the fact that the size of the dll (B.dll) swells when I statically link A.lib with it. However, when using it in an application, the MSVC compiler generates LNK2001 errors (symbol not found) for all of the functions in the static library!! (I guess you might be skeptic of some settings in my compiler; but trust me it is plain code!) Thanks for help again. (Btw,please respond to this question):confused:

                            I Offline
                            I Offline
                            Iain Clarke Warrior Programmer
                            wrote on last edited by
                            #13

                            richiehere wrote: First of all, thanks for all the 'activity' being generated on this thread! You're welcome. It beats real work (which I should be doing...) and is more satisfying than answering the "please do all my (home)work for me" questions that have been reappearing. I'll make an assumption that you have two projects in your workspace. B.DLL subproject, and C.EXE project that depends on the DLL. I would *strongly* suspect you are exposing A.LIB to to C.EXE, so it ends up linking to A.LIB too. Make sure that the exe does not include any of the headers associated with A.LIB, even implicitly. I'd bet you have a B.H file with the definitions from B.DLL that includes A.H. If B.H exposes any functions / classes that are not fully implemented in B.DLL, than C.EXE will need to link them from somewhere, or it will give errors... Its hard to be more specific without actually seeing your projects, so I'm having to be general here. Iain.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups