Static linking
-
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
-
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
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 -
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[^] SkyWalkerThank 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
-
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
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
-
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
-
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
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
-
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
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
-
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
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