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

被折叠的 条评论
为什么被折叠?



