Tools for inspecting .lib files?

Visual Studio

Visual Studio Problem Overview


I'm evaluating some underdocumented software. When I build a sample project, I'm getting a linker error that looks like:

error LNK2019: unresolved external symbol
There aren't a whole lot of lib files with this app, so I can solve this problem with trial and error, but I know there's a more elegant way is to solve this problem.

In the java world, I would grep FOO *.jar to find the jar and I'm looking for the C++ analog. I'm working with C++ code in Visual Studio 2005.

I suspect the lib.exe utility with the /LIST option can get the information, but I've been unsuccessful so far. It just prints this:

Microsoft (R) Library Manager Version 8.00.50727.762
Copyright (C) Microsoft Corporation.  All rights reserved.

granite50.dll granite50.dll granite50.dll granite50.dll ...

Any suggestions?

Visual Studio Solutions


Solution 1 - Visual Studio

First of all you need to know which type of library you are looking at. Some libraries simply contain linkages for a DLL (i.e., import libraries) and others are code objects that become part of the executable image (i.e., static libraries). From the looks of that output, you were looking at a DLL import library.

Next you want to use the right tool. Lib.exe is used to extract object files from libraries and what-not. This is pretty much the same as the jar utility for Java. Microsoft provides dumpbin.exe which will dump information from the library. I see that LarryF already mentioned this.

For import libraries, run dumpbin.exe -headers foo.lib and redirect it to an output file. The output will contain snippets for each symbol that the related DLL exports. Search for lines starting with " Symbol name :". Note that there are two spaces before and after "Symbol name" if you want an exact match. You can also run the output through findstr to generate a list of symbols and redirect that to a text file if you want something a little nicer to look at:

dumpbin.exe -headers foo.lib | findstr /c:"  Symbol name  :" > foo-exports.txt

The other option is to open the related DLL with depends.exe.

Solution 2 - Visual Studio

More than one thing can be your problem here. I'm not sure looking in the lib file will be the best way to solve it, IMHO... However, the DUMPBIN.exe is probably the tool you're looking for. Use it from the command line, but make sure your paths are set, or use the "Visual Studio Command Prompt" that VS installs for you in your VS start menu.

Solution 3 - Visual Studio

If you have a DLL and want to use it in your code with __declspec(dllimport) you can create the required LIB file easily if you have a DEF file for the DLL:

lib /def:mydll.def /nologo /machine:x86  

which creates mydll.lib

This command should be run in the Visual Studio SDK Command Prompt.

A DEF file can be written manually extremely easy if you don't have one: You open the DLL in DependencyWalker (http://www.dependencywalker.com), select "Save As" -> "Text with Import/Export lists" and have the names and ordinals of all exported functions in a txt file like this:

Export  Ordinal      Hint         Function                          Entry Point
------  -----------  -----------  --------------------------------  -----------
[C  ]    2 (0x0002)   1 (0x0001)  gsasl_base64_from                 0x000024F0
[C  ]    3 (0x0003)   2 (0x0002)  gsasl_base64_to                   0x000024A0
[C  ]    4 (0x0004)   3 (0x0003)  gsasl_callback                    0x000018B0
[C  ]    5 (0x0005)   4 (0x0004)  gsasl_callback_hook_get           0x00001900
[C  ]    6 (0x0006)   5 (0x0005)  gsasl_callback_hook_set           0x000018F0
[C  ]    7 (0x0007)   6 (0x0006)  gsasl_callback_set                0x000018A0
[C  ]    8 (0x0008)   7 (0x0007)  gsasl_check_version               0x00001870
[C  ]    9 (0x0009)   8 (0x0008)  gsasl_client_mechlist             0x00001E20
[C  ]   10 (0x000A)   9 (0x0009)  gsasl_client_start                0x00001F40

The rest is quickly done. Create a DEF file which has this format:

EXPORTS
gsasl_base64_from @2
gsasl_base64_to @3
gsasl_callback @4
gsasl_callback_hook_get @5
gsasl_callback_hook_set @6
gsasl_callback_set @7
gsasl_check_version @8
gsasl_client_mechlist @9
gsasl_client_start @10
gsasl_client_suggest_mechanism @11

The number behind the @ is the ordinal.


P.D: DependencyWalker can even undecorate cryptic names of C++ exports like

Foo@@YGHHH@Z   -->   int Foo(int, int). 

Solution 4 - Visual Studio

this worked with a visual C++ express 9 .lib :

dumpbin.exe -headers clangParse.lib | findstr /c:"COMDAT"  > clangParse-exports.txt

or

dumpbin.exe -headers clangParse.lib | findstr /c:"sym="  > clangParse-exports.txt

thank you d.shawley

Solution 5 - Visual Studio

open Visual Studio Command Prompt

dumpbin /all Effects11.lib > D:\1.txt

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncriddellView Question on Stackoverflow
Solution 1 - Visual StudioD.ShawleyView Answer on Stackoverflow
Solution 2 - Visual StudioLarryFView Answer on Stackoverflow
Solution 3 - Visual StudioElmueView Answer on Stackoverflow
Solution 4 - Visual StudioreunsView Answer on Stackoverflow
Solution 5 - Visual StudioKunMing XieView Answer on Stackoverflow