lib和DLL链接到一个exe混乱 [英] Lib and DLL linking to an exe confusion

查看:127
本文介绍了lib和DLL链接到一个exe混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个普遍的问题,关于如何使用.dll / .libs。我正在创建一个用于我的项目的.dll,但是,我注意到,当我去编译时,我需要静态链接.dib与.dll相关联的项目来编译(否则有链接错误致命错误LNK1107:无效或损坏的文件:无法读取0x300)。所以后来当我去redistrobute我的项目,然后更新它,将来,我需要运送一个新的.exe和一个新的.dll而不是一个新的.dll?如果是这样,那么为什么要使用.dll呢?

I have a general question about how .dll/.libs are suppose to be used. I am creating a .dll to be used for my project, however, I noticed that when I go to compile I need to statically link the .lib associated with the .dll for the project to compile (otherwise there is the linking error "fatal error LNK1107: invalid or corrupt file: cannot read at 0x300"). So later when I go redistrobute my project, then update it in the future, will I need to ship a new .exe and a new .dll rather than only a new .dll? If that is the case, then why bother using .dll's?

推荐答案

.lib包含功能等等的存根由DLL导出您将.lib链接到您的EXE中,现在您的EXE知道如何调用这些函数。但当然没有任何功能 - 呼叫无处可去。在加载的时候,当操作系统加载你的EXE时,它也会加载你的DLL,然后它将EXE调用EXE - 把这个EXE调用到存根中,加载器用一个调用替换为DLL中的实际函数。

The .lib contains stubs for the functions etc. that are exported by the DLL. You link the .lib into your EXE and now your EXE knows how to call the functions. But of course there's no function there - the calls go nowhere. At load time, when the operating system loads your EXE it also loads your DLL, and then it patches the EXE - where the EXE calls into the stub, the loader replaces that with a call into the real function in the DLL.

通常,您不需要将.lib发送给您的客户。但是,如果您的客户想要使用自己的DLL编写自己的EXE,那么您需要发送.lib,以便他们可以将EXE与其链接。

Normally you do not need to ship the .lib to your customers. However, if your customers want to write their own EXEs that use your DLL then you will need to send them the .lib so that they can link their EXE against it.

链接器错误LNK1107意味着您尝试链接到DLL而不是.lib。这总是错的,因为根据定义,DLL在运行时动态链接,而不是在构建时静态链接。

Linker error LNK1107 means that you've tried to link to the DLL rather than to the .lib. That's always wrong, because by definition a DLL is linked dynamically at runtime, rather than statically at build time.

这篇关于lib和DLL链接到一个exe混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆