Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tools for inspecting .lib files?

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?

like image 333
criddell Avatar asked Jan 28 '09 18:01

criddell


People also ask

How do I view the contents of a .LIB file?

a in unix. The windows equivalent is lib.exe /list libfile. lib . Yes lib will (only) show the obj files; it will not show the functions and data in the obj files.

What do .LIB files contain?

lib file contains all the code and data for the library. The linker then identifies the bits it needs and puts them in the final executable. For a dynamic library, the . lib file contains a list of the exported functions and data elements from the library, and information about which DLL they came from.

How do I run a .LIB exe file?

To run LIB, type the command lib , followed by the options and file names for the task you're using LIB for. LIB also accepts command-line input in command files, which are described in the following section. LIB doesn't use an environment variable.

What is .LIB file in Visual Studio?

In this article lib. Standard libraries contain objects and are created by the LIB tool. Import libraries contain information about exports in other programs and are created either by LINK when it builds a program that contains exports or by the LIB tool.


1 Answers

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.

like image 65
D.Shawley Avatar answered Sep 27 '22 22:09

D.Shawley