know if .lib is static or import

14,743

Solution 1

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

Solution 2

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.

Share:
14,743
zaharpopov
Author by

zaharpopov

Коммунизм!

Updated on June 07, 2022

Comments

  • zaharpopov
    zaharpopov almost 2 years

    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
    zaharpopov almost 13 years
    can you suggest which option(s) to give lib to perform this? I can't understand from its doc
  • tom_mai78101
    tom_mai78101 over 8 years
    @zaharpopov MSDN docs have been revamped since the release of Windows 8.1. Please check.
  • sean
    sean almost 7 years
    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.
  • truthadjustr
    truthadjustr about 5 years
    Your answer, in my opinion, is the better one. Thank you, i will adapt to your method. Before, I did it slightly differently: stackoverflow.com/questions/8019464/… but your lib method is the better method.
  • zois
    zois almost 3 years
    Trying this today on Windows 10, I got 'lib' is not recognized as an internal or external command, operable program or batch file.
  • Nicholas Jela
    Nicholas Jela about 2 years
    this is bad answer, please also let other know how to install lib command, since this command is not default avaible on any platform.
  • Artem
    Artem about 2 years
    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.
  • KcFnMi
    KcFnMi about 2 years
    __declspec(dllimport) is a thing of Microsoft compiler only afaik.
  • Breno
    Breno about 2 years
    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)