lua“存根”的目的是什么?适用于 Windows 的 DLL
我正在考虑将 Lua 合并到 C++ 项目中,并且对 Luabinaries。
根据文档...
在 Windows 中您的库或应用程序 必须与存根库链接。一个 存根库是一个只包含 函数声明将 将您的 DLL 与 Lua DLL 绑定。
为什么?我以前在与第三方 DLL 链接时从未需要过存根 DLL?
I'm looking at incorporating Lua into a C++ project, and am a bit confused by the presence of the two binaries (lua51.dll and lua5.1.dll) in the distribution from Luabinaries.
According to the docs...
In Windows your library or application
must be linked with a stub library. A
stub library is a library with only
the function declarations that will
bind your DLL with the Lua DLL.
Why? I've never needed stub DLLs before when linking with third-party DLLs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
存根库是一个
.lib
文件,而不是 DLL。它包含 DLL 中所有导出函数的函数声明,这些函数只是将调用转发到 DLL 本身。因此,如果您构建一个想要与 lua51.dll 链接的应用程序,您可以告诉链接器与 lua51.lib 链接,并且所有对导出函数的调用都将被转发到DLL。如果不这样做,链接时会出现很多“无法解析的外部符号”错误。仅当与 DLL 静态链接时才需要这样做(以便在应用程序运行时自动加载它)。使用
LoadLibrary
动态加载 DLL 时不需要它。关于为什么他们有两个不同的DLL,手册是这样说的:
基本上,一些现有的应用程序与 lua5.1.dll 链接,而其他应用程序与 lua51.dll 链接,并且他们希望同时支持它们。无论如何,这与存根库无关。
A stub library is a
.lib
file, not a DLL. It contains function declarations for all the exported functions in the DLL, which just forward the call into the DLL itself. So if you build an application that you want to link withlua51.dll
, you tell the linker to link withlua51.lib
, and all calls to exported functions will be forwarded to the DLL. If you didn't do this, you would get a lot of "unresolved external symbol" errors when linking.This is only needed when statically linking with a DLL (so that it is loaded automatically when the application is run). It is not needed when loading the DLL dynamically with
LoadLibrary
.Regarding why they have two different DLLs, The manual says this:
Basically, some existing applications link with
lua5.1.dll
while others link withlua51.dll
and they want to support them both. In any case this is not related to the stub libraries.我相信这与 __declspec(import) 和 __declspec(export) 与 GetProcAddress 有关。然而,我实际上并不确定。
I believe it's to do with __declspec(import) and __declspec(export) vs GetProcAddress. However, I don't actually know for sure.