Why am I getting the missing dll error after binding with .lib?

I have been working on this Windows program since 1999. I was unable to create it in Visual Studio, as it continued to give me linker errors regarding missing characters. Then my colleague told me to try to take .lib files from the source project and try to specify them as additional link dependencies. I did this and the program was fine. When I tried to start it, he complained about the lack of dll files. So I found an existing copy of a Windows program running on some old computer, copied the dll files, and my build started working! It was the happiest day of my life, but I do not quite understand what happened.

Can someone briefly explain what lib files are in Windows and how they relate to dll?

+4
source share
2 answers

On Windows, there are two .LIB files. Ken mentions one of them, which is intended for static binding, but there is another use called import library , which is here. If you create .DLL yourself, you have the opportunity to create an import library for it. The effect of this is that you can just reference the .LIB file as you would a regular static library, but .LIB actually just contains the template code for loading the entry points from the DLL.

The reason for this is that you may need to distribute the code as a dll (for example, so that you can update it independently of the main application or provide a DLL as a plugin), but it simplifies the binding to it, .LIB processes calls to LoadLibrary() and GetProcAddress() therefore you do not need. It can also load class definitions from dlls that you cannot do with GetProcAddress() yourself.

Additional MSDN Information

+4
source

.LIB (library) are collections of compiled source files (object files) that you can link to your application to provide functionality. Linking makes object files part of your executable. This is usually called static linking , and why you got a compile-time error about missing characters; library files were not available to extract the necessary object code to add to your application.

.DLL (dynamic link library) - these are compiled source files that can be loaded at run time and used certain functions (usually by name); they are not part of your executable, but are loaded at runtime from the DLL itself. (Having no DLLs available, as you have already seen, means that your application does not start.) They are not needed at compile time, but only at runtime.

Some IDEs (for example, Visual Studio C / C ++) create both a static .LIB file and a .DLL version, so you can choose to run-time libraries directly link to your application or provide them to dynamically load at runtime. (The second is useful, for example, if you have several applications that you have developed, you can use the dynamic version of MSVCRTL to drastically reduce the size of your executable files by distributing the RTL separately, and not be bundled in each application.

0
source

Source: https://habr.com/ru/post/1402324/


All Articles