1

I'm a little confused as to why a 3rd party .dll I'm using comes with a .lib file labeled as an "import library." When I run the program, I just place the .dll in the same directory as the executable and it works. I'm using MinGW.

Could someone explain why the .dll comes with a .lib import library if I don't even need it? How would I even use it and where should I put it if I did use it with MinGW?

I read up on it and it looks like the .lib file is not needed by MinGW (what I'm using) and is needed by MSVC. Why is this?

P.S. If I wanted to put a .dll in a directory other than the directory containing the executable, could I put a line in the .pro file to point to it?

genpfault
  • 51,148
  • 11
  • 85
  • 139
earth
  • 945
  • 1
  • 10
  • 27
  • 3
    Possible duplicate of [How does the Import Library work? Details?](http://stackoverflow.com/questions/3573475/how-does-the-import-library-work-details) – ivan_pozdeev Feb 15 '16 at 07:30
  • 1
    I read that. It does not get at the question about MinGW and MSVC requirements, though. – earth Feb 15 '16 at 07:38
  • 1
    related: http://stackoverflow.com/questions/2472924/linking-to-msvc-dll-from-mingw – ivan_pozdeev Feb 15 '16 at 08:20

1 Answers1

2

According to http://www.mingw.org/wiki/sampleDLL, MinGW can guess the information that's contained in a .lib (DLL name, exported entries' names and ABI) from the corresponding .h file and the DLL itself.

According to http://www.mingw.org/wiki/CreateImportLibraries, this works "for all DLLs created with MinGW and also a few others".

In cases when it can't guess correctly, you still need to provide a .lib file. The latter link has instructions on how to generate one by hand if you haven't got a pristine one.

The former link refers to ld docs for a more in-depth description. Specifically, it's at the ld and WIN32 (cygwin/mingw) node, "direct linking to a dll" section. Among other things, it outlines cases when a .lib is necessary:

  • until recently, direct linking didn't work for exported data entries
  • if a .lib contains pure static objects (e.g. cygwinX.dll)
  • if exported entries do not conform to mangling rules (e.g. Win32 libraries)
0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152