c++winapilinker

When building a DLL file, does the generated LIB file contain the DLL name?


In Visual C++ , when I build a dll , the output files are .dll and .lib.

Is the name of the dll built into the .lib file .

The reasson I ask this question is : When I built my exe by importing this dll and run the exe , the exe tries to locate the dll to load it in the process address space .

As we just specify the library name (.lib file) in the project properties , how does the exe get to know the name of the dll .

Note : I dumpbin libary file (.lib) and saw that it does not contain the name of the dll .


Solution

  • The LIB file is turned into an import table in the EXE. This does contain the name of the DLL.

    You can see this if you run dumpbin /all MyDLL.lib. Note that dumpbin MyDll.lib by itself doesn't show anything useful: you should use /all.

    This shows all of the sections defined in the .LIB file. You can ignore any .debug sections, because they wouldn't be present in a Release build. In the .LIB file, there are a collection of .idata sections. In the DLL project that I just built, the LIB file contains a .idata$4 section which defines the symbols to be put in the EXE's import table, including the DLL name:

    Archive member name at 83E: MyDll.dll/      
    497C3B9F time/date Sun Jan 25 10:14:55 2009
             uid
             gid
           0 mode
          2E size
    correct header end
    
      Version      : 0
      Machine      : 14C (x86)
      TimeDateStamp: 497C3B9F Sun Jan 25 10:14:55 2009
      SizeOfData   : 0000001A
      DLL name     : MyDll.dll
      Symbol name  : ?fnMyDll@@YAHXZ (int __cdecl fnMyDll(void))
      Type         : code
      Name type    : name
      Hint         : 2
      Name         : ?fnMyDll@@YAHXZ