为什么某些DLL文件需要一个附加的.lib文件进行链接? [英] Why do some DLL files need an additional .lib file for linking?

查看:85
本文介绍了为什么某些DLL文件需要一个附加的.lib文件进行链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对库链接和.lib文件有疑问...

I have a question about library linking and .lib files...

这是上下文:


  • 操作系统= Windows

  • IDE = QT

I已经创建了一个DLL:MyLib.dll。

要在我的QT项目中使用该库,我只需要包括一个include路径,该库的链接并使用头文件:

I have created a DLL: MyLib.dll.
To use that library in my QT project, I only have to include an include path, a link to the library and use the header files:

LIBS += "C:\myPath\MyLib.dll"
INCLUDEPATH += "C:\myPath"
HEADERS += \
    ../myPath/MyLib_global.h \
    ../myPath/mylib.h

我在我的项目中使用了第三方dll:third.dll

如果我执行与上述示例相同的操作,则它将不起作用:

I am using a third party dll in my project: third.dll
If I do the same as in the above example, it does not work:

LIBS += "C:\myPath\third.dll" 

第三方DLL带有一个.lib文件 third.lib,我显然需要将其与DLL一起使用。

The third party DLL comes with a .lib file "third.lib", which I apparently need to use together with the DLL.

为什么?为什么有些DLL库需要一个.lib文件,而其他DLL库却不需要?

可能是.lib是访问DLL的静态库吗?

Why is that? Why do some DLL libraries need a .lib file but other DLL libraries don't?
Could it be that the .lib is a static library accessing the DLL?

非常感谢!

推荐答案

lib文件是一个导入库文件,它允许最终的可执行文件包含一个导入地址表(IAT),通过该地址表引用所有DLL函数调用。基本上,允许查找功能。

The lib file is an import library file, which allows the final executable to contain an import address table (IAT) by which all DLL function calls are referenced. Basically, allowing the functions to be looked up.

您可以阅读此处

要让Qt生成库,请将其添加到.pro中:-

To have Qt generate the lib, add this to the .pro: -

CONFIG+= staticlib

此处有关如何创建库的一些文档。

Here's some documentation on how to create libraries.

这篇关于为什么某些DLL文件需要一个附加的.lib文件进行链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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