关于.lib和.dll的一点说明

本文详细介绍了在Visual Studio中如何使用DLL文件,并解释了DLL与LIB文件之间的关系。要使用DLL,需要配置附加依赖项,添加相应的LIB文件,并确保DLL文件位于正确的路径下。此外,还介绍了如何通过#pragmacomment指令实现相同的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

         在vs中,我们要是使用.dll的话必须要设置配置属性->链接器->输入->附加依赖项,我们在自己创建dll文件的时候会同时创建一个.lib文件,dll文件和lib文件的关系就是lib文件提供了dll文件的访问接口,我们先要在连接器中添加.lib文件,还要将.dll文件放到环境变量所指的目录中(或者当前目录就是和.exe文件在同一级目录)。还可以通过#pragma comment的预编译命令来添加.lib文件,效果是和在连接器中设置时一样的。

        自己的一点理解,欢迎讨论!

        理解来自一些描述:

        In C++, you would go, in the project configuration, to Linker->Input->Additional Dependencies. There, you would list the library name plus path to the .lib in question.

Normally, when you build a Windows C/C++ DLL, you also get a .lib. This is an import library; users of the library include (as stated above) that .lib in order to access the DLL. They generally do not load the .dll directly (though there are ways to do that).     

#pragma comment is a compiler directive which indicates Visual C++ to leave a comment in the generated object file. The comment can then be read by the linker when it processes object files.

#pragma comment(lib, libname) tells the linker to add the 'libname' library to the list of library dependencies, as if you had added it in the project properties atLinker->Input->Additional dependencies.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值