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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Static linking

Static linking

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharphelptutorialquestion
8 Posts 3 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.
  • S Offline
    S Offline
    serious sam
    wrote on last edited by
    #1

    Hello all, Could anyone explain how to link a library statically into an executable in Visual C++ .NET? My problem is that I'm compiling against library (.lib) files, but I do not have the corresponding (.dll) files. The compilation works fine, but when I attempt to run the application, it falls over as it is not able to find the .dll. It is my understanding that if I statically link the required parts from the .lib files into the executable, it will have everything it needs at run-time and will not go off looking for the .dll. I've looked around the compiler and linker settings within Visual C++ and haven't been able to find anything to make me happy. Googling hasn't produced anything either. Could someone suggest a solution? Cheers, Penkov

    Mircea PuiuM C 2 Replies Last reply
    0
    • S serious sam

      Hello all, Could anyone explain how to link a library statically into an executable in Visual C++ .NET? My problem is that I'm compiling against library (.lib) files, but I do not have the corresponding (.dll) files. The compilation works fine, but when I attempt to run the application, it falls over as it is not able to find the .dll. It is my understanding that if I statically link the required parts from the .lib files into the executable, it will have everything it needs at run-time and will not go off looking for the .dll. I've looked around the compiler and linker settings within Visual C++ and haven't been able to find anything to make me happy. Googling hasn't produced anything either. Could someone suggest a solution? Cheers, Penkov

      Mircea PuiuM Offline
      Mircea PuiuM Offline
      Mircea Puiu
      wrote on last edited by
      #2

      Use /ML, /MLd, /MT, /MTd See details here: http://msdn.microsoft.com/library/?url=/library/en-us/vclib/html/_crt_c_run.2d.time_libraries.asp[^] SkyWalker

      S 1 Reply Last reply
      0
      • Mircea PuiuM Mircea Puiu

        Use /ML, /MLd, /MT, /MTd See details here: http://msdn.microsoft.com/library/?url=/library/en-us/vclib/html/_crt_c_run.2d.time_libraries.asp[^] SkyWalker

        S Offline
        S Offline
        serious sam
        wrote on last edited by
        #3

        Thank you for your reply. The options you suggested seem to apply only to the standard C run-time libraries which are provided by MS. My problem is that I need to statically link to my own libraries. I've tried playing around with the /link option, but I have not had any luck with it. Do you have any other suggestions? Thanks in advance. Penkov

        Mircea PuiuM 1 Reply Last reply
        0
        • S serious sam

          Thank you for your reply. The options you suggested seem to apply only to the standard C run-time libraries which are provided by MS. My problem is that I need to statically link to my own libraries. I've tried playing around with the /link option, but I have not had any luck with it. Do you have any other suggestions? Thanks in advance. Penkov

          Mircea PuiuM Offline
          Mircea PuiuM Offline
          Mircea Puiu
          wrote on last edited by
          #4

          I review your first question, where you say you do not have the dll. You must have the dll if you want to work with it!! Now, assuming that you do have your own dll, you could try importing the idl file. See a MSDN example for ATL here: http://support.microsoft.com/?scid=kb;en-us;832687&spid=2990&sid=1134[^] SkyWalker

          1 Reply Last reply
          0
          • S serious sam

            Hello all, Could anyone explain how to link a library statically into an executable in Visual C++ .NET? My problem is that I'm compiling against library (.lib) files, but I do not have the corresponding (.dll) files. The compilation works fine, but when I attempt to run the application, it falls over as it is not able to find the .dll. It is my understanding that if I statically link the required parts from the .lib files into the executable, it will have everything it needs at run-time and will not go off looking for the .dll. I've looked around the compiler and linker settings within Visual C++ and haven't been able to find anything to make me happy. Googling hasn't produced anything either. Could someone suggest a solution? Cheers, Penkov

            C Offline
            C Offline
            cmk
            wrote on last edited by
            #5

            A static library .lib file is not the same as a .lib file used to link to a dll. The static lib .lib file has all the compiled code. The dll .lib file only has the export information for the dll. ...cmk Save the whales - collect the whole set

            S 1 Reply Last reply
            0
            • C cmk

              A static library .lib file is not the same as a .lib file used to link to a dll. The static lib .lib file has all the compiled code. The dll .lib file only has the export information for the dll. ...cmk Save the whales - collect the whole set

              S Offline
              S Offline
              serious sam
              wrote on last edited by
              #6

              Thank you for your reply.

              cmk wrote:

              A static library .lib file is not the same as a .lib file used to link to a dll.

              I was under the impression that they are all static libraries... Could you please elaborate? How do I distinguish between one type of .lib file and another? I haven't done much Windows C++ development (up until now only had to work on Linux). If you could point me in the direction where I can read a bit more about this, it would be great. Thanks again, Penkov

              C 1 Reply Last reply
              0
              • S serious sam

                Thank you for your reply.

                cmk wrote:

                A static library .lib file is not the same as a .lib file used to link to a dll.

                I was under the impression that they are all static libraries... Could you please elaborate? How do I distinguish between one type of .lib file and another? I haven't done much Windows C++ development (up until now only had to work on Linux). If you could point me in the direction where I can read a bit more about this, it would be great. Thanks again, Penkov

                C Offline
                C Offline
                cmk
                wrote on last edited by
                #7

                misha1983 wrote:

                I was under the impression that they are all static libraries... Could you please elaborate? How do I distinguish between one type of .lib file and another?

                No, they are not all static libraries. As i mentioned, you get different .lib files from building a project as a static lib vs a dll. There is no obvious way to distinguish, you are usually told when you get the file(s). If you know more about what to expect in these files then you can use a hex editor to look at their contents and tell from that, but explaining that is too involved. You are usually either given a x.lib and told 'this is a static lib build of our x API', or you are given a x.lib, x.exp and x.dll and told 'here is our x API dll'. Actually there is a 3rd option, you are given a x.lib, x.exp and x.exe and told 'here is our application, which exports our y API'. Search MSDN for information on lib, e.g. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_running_lib.asp[^] ...cmk Save the whales - collect the whole set

                S 1 Reply Last reply
                0
                • C cmk

                  misha1983 wrote:

                  I was under the impression that they are all static libraries... Could you please elaborate? How do I distinguish between one type of .lib file and another?

                  No, they are not all static libraries. As i mentioned, you get different .lib files from building a project as a static lib vs a dll. There is no obvious way to distinguish, you are usually told when you get the file(s). If you know more about what to expect in these files then you can use a hex editor to look at their contents and tell from that, but explaining that is too involved. You are usually either given a x.lib and told 'this is a static lib build of our x API', or you are given a x.lib, x.exp and x.dll and told 'here is our x API dll'. Actually there is a 3rd option, you are given a x.lib, x.exp and x.exe and told 'here is our application, which exports our y API'. Search MSDN for information on lib, e.g. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_running_lib.asp[^] ...cmk Save the whales - collect the whole set

                  S Offline
                  S Offline
                  serious sam
                  wrote on last edited by
                  #8

                  Ok, thanks, that's cleared it up a bit. I've asked around work and managed to dig up the DLLs I needed. So that's taken care of. Thanks to both of you for helping. Cheers, Penkov

                  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