什么是里面的.lib文件的静态库,静态链接的动态库和动态链接的动态库?

问题描述:

静态库,静态链接的动态库和动态链接的动态库的.lib文件里面是什么?

What is inside of a .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?

怎么不需要.lib文件在动态链接的动态库,而且在静态链接,.lib文件只是一个.obj文件与所有的方法。是否正确?

How come there is no need for a .lib file in dynamically linked dynamic library and also that in static linking, the .lib file is nothing but a .obj file with all the methods. Is that correct?

对于静态库,.lib文件包含库的所有代码和数据。链接器然后标识它需要的位并将它们放在最终可执行文件中。

For a static library, the .lib file contains all the code and data for the library. The linker then identifies the bits it needs and puts them in the final executable.

对于动态库,.lib文件包含导出的函数和数据元素的列表从库,以及关于它们来自哪个DLL的信息。当链接器构建最终可执行文件时,如果使用来自库的任何函数或数据元素,则链接器添加对DLL的引用(使其由Windows自动加载),并向可执行文件的导入表添加条目

For a dynamic library, the .lib file contains a list of the exported functions and data elements from the library, and information about which DLL they came from. When the linker builds the final executable then if any of the functions or data elements from the library are used then the linker adds a reference to the DLL (causing it to be automatically loaded by Windows), and adds entries to the executable's import table so that a call to the function is redirected into that DLL.

你不需要一个.lib文件来使用动态库,但没有一个你不能处理的函数DLL在你的代码中作为正常的函数。相反,您必须手动调用 LoadLibrary 加载DLL(和完成后加载 FreeLibrary ),然后 GetProcAddress 以获取DLL中的函数或数据项的地址。然后,必须将返回的地址转换为适当的指针到函数才能使用。

You don't need a .lib file to use a dynamic library, but without one you cannot treat functions from the DLL as normal functions in your code. Instead you must manually call LoadLibrary to load the DLL (and FreeLibrary when you're done), and GetProcAddress to obtain the address of the function or data item in the DLL. You must then cast the returned address to an appropriate pointer-to-function in order to use it.