.h header file .lib dynamic link library file .dll dynamic link library

(1) .h header files is a must compile-time, lib is needed link, dll is needed at runtime.

附加依赖项的是.lib 不是.dll 

若生成了DLL ,则肯定也生成 LIB文件

If you want to compile and link the source code, header files and lib enough.
If the program makes a dynamic connection up and running, there are dll enough.
In the development and debugging phase, of course, the best there.

.H .lib .dll relationship between the three is:

H文件 作用是:声明函数接口 

DLL文件 作用是: 函数可执行代码 

当我们在自己的程序中引用了一个H文件里的函数,编链器怎么知道该调用哪个DLL文件呢? 

这就是LIB 文件的作用: 告诉链接器 调用的函数在哪个DLL中,函数执行代码在DLL中的什么位置 

这也就是为什么需要 附加依赖项 .LIB文件 ,它起到桥梁的作用。

如果生成静态库文件,则没有DLL ,只有lib,这时函数可执行代码部分也在lib文件中

目前以lib后缀的库有两种,一种为静态链接库


(Static  Libary,以下简称“静态库”),另一种为动态连接库(DLL,以下简称“动态库”)的导入库


(Import  Libary,以下简称“导入库”)。 

静态库是一个或者多个obj文件的打包,所以有人干脆把从obj文件生成lib的过程称为Archive,即合并到一起。比如你链接一个静态库,如果其中有错,它会准确的找到是哪个obj有错,即静态lib只是壳子。   
动态库一般会有对应的导入库,方便程序静态载入动态链接库,否则你可能就需要自己LoadLibary调入DLL文件,然后再手工GetProcAddress获得对应函数了。有了导入库,你只需要链接导入库后按照头文件函数接口的声明调用函数就可以了。

导入库和静态库的区别很大,他们实质是不一样的东西。静态库本身就包含了实际执行代码、符号表等等,而对于导入库而言,其实际的执行代码位于动态库中,导入库只包含了地址符号表等,确保程序找到对应函数的一些基本地址信息。 

(2) the general dynamic library program have lib files and dll files. lib file is a must even received an application at compile time, but dll file is run will be called. If there dll file, then the corresponding lib file is usually some of the index information, the specific implementation in the dll file. If only the lib file, then this is statically compiled lib file out, and implementation in which the index. Statically compiled lib file is good: there is no need for the user to install a dynamic library and then hang up. But there are drawbacks that led to large applications, but also lose the flexibility of dynamic libraries, during version upgrades, and to publish a new application for the job.
(3) In the case of dynamic library, there are two files, a library is introduced (the .LIB) file is a DLL file, import library file contains the names and location of the function exported by the DLL, the DLL function contains the actual and data, the application uses a DLL file LIB file is linked to the need to use, library functions and data is not copied into the executable file, so the application's executable file, stored in function code is not being called , but the memory address of the function in the DLL to be called, so that when one or more applications are then run program code and the function code is called linked, thus saving memory resources. As can be seen from the above description, DLL, and .LIB files must be issued together with the application, otherwise the application will generate an error.


Add .LIB files in VS2008

Method One: In the project Properties -> Linker -> Input -> Additional Dependencies

In the above path can join multiple names separated by a space lib

 

Act II: directly reflected in the code:

#pragma comment (lib, "winmm.lib") // adding winmm.lib library

Reproduced in: https: //my.oschina.net/dake/blog/196650

Guess you like

Origin blog.csdn.net/weixin_33885253/article/details/91508140