14

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 .

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380

3 Answers3

21

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
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • yeah the exe's import section contains the name of the dll . But it get to know the name from the library as you say . So , do you mean the library contains the name . If yes , why dont I see that when I dumpbin the library . –  Jan 25 '09 at 10:24
  • ...because you're not running DUMPBIN correctly? Pass the /ALL switch, and then you should see output similar to what I included. – Roger Lipscombe Jan 25 '09 at 10:29
  • Thanks . I get the concept now . –  Jan 25 '09 at 10:30
2

Yes, the lib contains the name of the DLL.

Functionally, the import library implements the LoadLibrary and GetProcAdress calls, and makes the exported functions available as if they were linked statically.

The search path is the same as documented for LoadLibrary, the name is fixed, though.

peterchen
  • 40,917
  • 20
  • 104
  • 186
0

As pointed out by Roger and Peter, yes the .lib file contains the name of the .dll file. And thanks to Roger for pointing out dumpbin shows the name of the .dll file, this helped me solve my problem. Which relates to where the name in the .lib file comes from.

I was expecting the name to be taken from the project settings for the dll project but we had an export.def which specified the name for the dll. So we had problems using our dll when I changed the project settings but not the export.def. The solution for our project was to wipe out the export.def file.

Bowie Owens
  • 2,798
  • 23
  • 20