简体   繁体   English

Windows应用程序需要在编译时了解DLL吗

[英]Do Windows applications need to know about DLLs at compile time

I have searched the web , but with different answers to my query. 我已经在网上搜索过,但是对我的查询有不同的答案。 I am not an expert with Windows but I would like to understand it exactly. 我不是Windows方面的专家,但我想完全了解它。

When an application is compiled for Windows, which will involve the need for runtime-linking of libraries (DLLs), like using a core library kernel32.dll or some other user-created dll, does the application need to know that the dll exists before run-time. 当为Windows编译应用程序时,这需要对库(DLL)进行运行时链接,例如使用核心库kernel32.dll或其他一些用户创建的dll,该应用程序是否需要知道该dll在存在之前运行。

I have read that a dll must be accompanied by a .lib file which must be linked in at compile time but somewhere it states that the .lib file is not required. 我已经读过,dll必须附带一个.lib文件,该文件必须在编译时链接到其中,但它在某处指出该.lib文件不是必需的。

Does the application just execute and expect that it will find the functions needed in a dll and just fail if not found? 应用程序是否只是执行并期望它会在dll中找到所需的功能,如果找不到,就会失败?

Thanks in advance. 提前致谢。

List of dynamically linked functions is kept in import section of PECOFF executable file, as defined with the second directory item in optional header. 动态链接函数的列表保存在PECOFF可执行文件的import部分中,如可选标头中的第二个目录项所定义。 Usual name of the section is .idata or IMPORT . 该部分的常规名称是.idataIMPORT The only necessary information kept in the import directory is 导入目录中保留的唯一必要信息是

  1. name of the function 功能名称
  2. filename of the dynamic library (without path) 动态库的文件名(无路径)

So the answer is negative, linker does not need to know anything about the DLL and it doesn't necessarily need to exist at link-time. 因此答案是否定的,链接器不需要了解有关DLL的任何信息,并且链接时不一定必须存在它。 It is the loader's job to find the refered DLL at run-time (and report error Entry point FunctionName was not found in the library eventually). 在运行时查找引用的DLL是加载程序的工作(并且最终在库中找不到报告错误入口点FunctionName )。

Import libraries .lib exist because of older compilers and linkers which lack the directive to declare imported function and its DLL, so they need the linked library which contains import definition and also indirect proxy jumps to IAT. 导入库.lib之所以存在,是因为较早的编译器和链接器缺少声明导入函数及其DLL的指令,因此它们需要包含导入定义以及间接代理跳转到IAT的链接库。 But good linker doesn't need this, as this information can be created on the fly. 但是好的链接器不需要它,因为可以即时创建此信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM