67

I have .lib file compiled from C code. How I know if this self-contained static library or just an import lib and DLL will be needed at runtime? Is there some dumpbin option I'm missing?

zaharpopov
  • 16,112
  • 23
  • 74
  • 91
  • Strange question. If you don't have the DLL then you can only cross your fingers. – Hans Passant Jun 19 '11 at 16:25
  • 2
    Normally you would read the documentation. If you don't have documentation and don't know the provenance of the .lib then you should think twice about using it. – David Heffernan Jun 19 '11 at 16:31
  • 6
    Sadly, many libraries come with "getting started" or "readme" files that are out of date, and some mysterious hidden option to configure if it's building static or dynamic. This gets worse when it's not even a library I want, but one needed by a library that I want. – AndrewS Sep 18 '13 at 22:37

2 Answers2

82

Use the lib command. If it's static, lib will show you a pile of .obj files inside. Not so if it's am implib.

lib /list foo.lib

will do it.

Also see:

https://docs.microsoft.com/en-us/cpp/build/reference/managing-a-library

Adam Rosenfield
  • 375,615
  • 96
  • 501
  • 581
bmargulies
  • 94,623
  • 39
  • 172
  • 299
  • 1
    can you suggest which option(s) to give `lib` to perform this? I can't understand from its doc – zaharpopov Jun 20 '11 at 05:02
  • @zaharpopov MSDN docs have been revamped since the release of Windows 8.1. Please check. – tom_mai78101 Jan 21 '16 at 06:49
  • @user31389, you should suggest that as a separate answer so that it will get more attention. – Alan Dec 08 '16 at 15:05
  • 4
    There seems to be a similar way. Open the lib file with 7zip. If it's an imort lib, it would contain *.dll files. Otherwise, it would contain *.obj files, maybe in a folder. – sean Jun 08 '17 at 04:51
  • Your answer, in my opinion, is the better one. Thank you, i will adapt to your method. Before, I did it slightly differently: https://stackoverflow.com/questions/8019464/static-library-v-s-import-library-on-windows-platform/51861571#51861571 but your `lib` method is the better method. – eigenfield Mar 29 '19 at 08:32
  • Trying this today on Windows 10, I got `'lib' is not recognized as an internal or external command, operable program or batch file.` – zois Jul 28 '21 at 18:18
  • this is bad answer, please also let other know how to install `lib` command, since this command is not default avaible on any platform. – Nicholas Jela Apr 06 '22 at 06:22
  • 1
    Windows is only one platform, and this question is about windows, and the lib command comes with the windows SDK, which you need to have to do any development. – bmargulies Apr 06 '22 at 20:51
  • If you have Visual Studio installed, there is a lib.exe there, as well. If you install the Community edition, 2019, it will be somewhere like "C:\Program Files (x86)\ Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\##.##.#####\bin\Hostx64\x64\". The "##.##.#####" are a bunch of numbers, which I'm not sure what are... maybe a specific version? Plus, if you need the executable for 32 bit windows there are other folders there as well (e.g. Hostx32) – Breno May 04 '22 at 19:19
5

Look in its accompanying header files ,if the function are 'decorated' with __declspec(dllimport) that it's an import library. Or look for an accompanying .def file ,that also tells you that it's an import library.

Puppy
  • 141,834
  • 35
  • 244
  • 454
engf-010
  • 3,892
  • 1
  • 13
  • 24