链接到exe错误的库和DLL错误“无法在0x300读取". [英] Lib and DLL linking to an exe error "cannot read at 0x300"

查看:148
本文介绍了链接到exe错误的库和DLL错误“无法在0x300读取".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对应该如何使用.dll/.lib有一个一般性的问题.我正在创建一个用于项目的.dll,但是,我注意到在进行编译时,我需要静态链接与.dll相关联的.lib,以便项目进行编译(否则,存在链接错误致命"错误LNK1107:无效或损坏的文件:无法读取0x300).因此,当我以后重新发行项目时,然后在将来对其进行更新时,是否需要运送新的​​.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调用到存根的位置,加载器将其替换为对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.

这篇关于链接到exe错误的库和DLL错误“无法在0x300读取".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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