在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.