具有 DLL 依赖项、未解析的外部符号的 Visual Studio DLL 项目
我对 Windows 概念很陌生。我正在尝试开发一个也可以动态链接其他 DLL 的 DLL。我正在使用 Visual Studio 2010。在链接时,Visual studio 告诉我它正在尝试链接一堆 .lib 文件。如果我希望我的代码执行动态链接,我认为 Visual Studio 不应尝试读取任何 .LIB 文件,这样正确吗?或者我对.LIB文件的使用还不够了解?
谢谢
I'm new to Windows concepts. I'm trying to develop a DLL that also dynamically links against other DLL's. I'm using Visual Studio 2010. At linking time Visual studio tells me it's trying to link against a bunch of .lib files. I don't think Visual Studio should attempt to read any .LIB files if I want my code to perform dynamic linking is that correct? Or do I not understand the use of .LIB files enough?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的理解是,你有点困惑,因为你想使用 DLL 而不是 LIB。
诀窍在于 Kernel32.Lib、User32.Lib、AdvAPI32.Lib 等没有实现您使用的函数。此外,如果您在程序中使用诸如
CreateFileW
或MessageBoxW
之类的函数,则在编译后对该函数的引用将无法解析。因此,如果没有 LIB,未解析的引用也将保留在 EXE 中。这将是有原因的坏事。为了可执行,EXE 必须解析所有外部引用,并且准确地知道应该在哪些 DLL 中找到哪些函数。所以命名导入库有助于解决问题。例如,导入库 Kernel32.Lib 包含有关CreateFileW
函数的信息,User32.Lib 包含有关MessageBoxW
的信息。如果您使用 Kernel32.Lib、User32.Lib、AdvAPI32.Lib 等导入库列表,您的 EXE 会解析所有引用的内容,并包含其所需的 DLL 的确切列表以及特殊 中相应 DLL 中使用的函数列表。 >导入表(参见http://en.wikipedia.org/wiki/Portable_Executable #Import_Table,http://msdn.microsoft.com/en -us/library/ms809762.aspx 和 http:// /www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx)。因此,如果启动 EXE,操作系统会将 DLL 加载到进程的地址空间中,并解析直到最后为止所有引用,直到使用的所有函数的地址。通常,当编译 DLL 时,链接器 (link.exe) 将创建导入库。还可以创建一个与 lib.exe 实用程序相关的 DLL 对应的导入库。 (请参阅http://msdn.microsoft.com/en-us/library/ 0b9xe492.aspx)
How I understand, you are a little confused, because you want to use DLLs instead of LIBs.
The trick is that Kernel32.Lib, User32.Lib, AdvAPI32.Lib and so on has no implementation of the function which you use. Moreover if you use functions like
CreateFileW
orMessageBoxW
in your program the references to the function will be unresolved after the compilation. So without having LIBs the unresolved references will stay also in the EXE. That will be bad of cause. To be executable the EXE must have resolved all external references and moreover know exactly which functions should be found in which DLLs. So named import library help to solve the problem. The import library Kernel32.Lib for example has information aboutCreateFileW
function and User32.Lib has information aboutMessageBoxW
. If you use a list of import libraries like Kernel32.Lib, User32.Lib, AdvAPI32.Lib your EXE resolves all referenced and includes the exact list of DLLs which it need and the list of functions used in the corresponding DLL in a special Import table (see http://en.wikipedia.org/wiki/Portable_Executable#Import_Table, http://msdn.microsoft.com/en-us/library/ms809762.aspx and http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx). So If one starts your EXE the operation system loads the DLL in the address space of the process and resolves till the end all references up to the addresses of all functions used.Typically import libraries will be created by linker (link.exe) when one compile a DLL. It is also possible to create an import library which corresponds to the DLL with respect of lib.exe utility. (see http://msdn.microsoft.com/en-us/library/0b9xe492.aspx)
我记得,Visual Studio 的编译器通过链接存根 .LIB 文件来解析 .DLL 文件。
检查一下,其中之一应该是kernel32.lib。
As I recall, Visual Studio's compiler resolves .DLL files by linking against stub .LIB files.
Check, one of them should be kernel32.lib.