为什么我需要一个lib文件链接到我的项目? [英] why do I need to link a lib file to my project?

查看:77
本文介绍了为什么我需要一个lib文件链接到我的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个使用DLL的项目。要建立我的项目,我需要包含一个头文件和库文件。为什么我需要包括相应的​​库文件?不应该在头文件中声明所需的所有信息,然后在运行时加载任何需要的库/ DLL?

I am creating a project that uses a DLL. To build my project, I need to include a header file, and a lib file. Why do I need to include the respective lib file? shouldn't the header file declare all the needed information and then at runtime load any needed library/dll?

感谢

推荐答案

在许多其他语言,头文件就相当于是你所需要的。但是,在Windows中常见的C链接器一直使用的导入库,C ++链接器紧随其后,它可能为时已晚来改变。

In many other languages, the equivalent of the header file is all you need. But the common C linkers on Windows have always used import libraries, C++ linkers followed suit, and it's probably too late to change.

这样作为一个思想实验,人们可以想像语法:

As a thought experiment, one could imagine syntax like this:

__declspec(dllimport, "kernel32") void __stdcall  Sleep(DWORD dwMilliseconds);

使用该信息的编译器/连接器工具链可以做其余的武装。

Armed with that information the compiler/linker tool chain could do the rest.

作为进一步的例子,在Delphi人会导入此功能,采用隐式链接,像这样:

As a further example, in Delphi one would import this function, using implicit linking, like so:

procedure Sleep(dwMilliseconds: DWORD); stdcall; external 'kernel32';

这只是显示了导入库都没有,先验的,必不可少的链接DLL文件。

which just goes to show that import libraries are not, a priori, essential for linking to DLLs.

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

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