Lib and DLL linking to an exe error quot;cannot read at 0x300quot;(链接到 exe 错误“无法读取 0x300的 Lib 和 DLL)
问题描述
我有一个关于 .dll/.libs 应该如何使用的一般性问题.我正在创建一个用于我的项目的 .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 错误“无法读取 0x300"的 Lib 和 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:链接到 exe 错误“无法读取 0x300"的 Lib 和 DLL
- 近似搜索的工作原理 2021-01-01
- 静态初始化顺序失败 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- C++ 协变模板 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01