visual-studio 检查 .lib 文件的工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/488809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:06:48  来源:igfitidea点击:

Tools for inspecting .lib files?

visual-studio

提问by criddell

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 elegantway is to solve this problem.

这个应用程序没有很多 lib 文件,所以我可以通过反复试验来解决这个问题,但我知道有一个更优雅的方法来解决这个问题。

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

在 Java 世界中,我会grep FOO *.jar来查找 jar 并且我正在寻找 C++ 模拟。我正在 Visual Studio 2005 中使用 C++ 代码。

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:

我怀疑带有 /LIST 选项的 lib.exe 实用程序可以获取信息,但到目前为止我一直没有成功。它只是打印这个:

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?

有什么建议?

回答by D.Shawley

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.

首先,您需要知道您正在查看哪种类型的库。一些库仅包含DLL 的链接(即,导入库),而其他库是成为可执行映像的一部分的代码对象(即,静态库)。从该输出的外观来看,您正在查看 DLL 导入库。

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 LarryFalready mentioned this.

接下来您要使用正确的工具。Lib.exe 用于从库和其他内容中提取目标文件。这与 Java 的 jar 实用程序几乎相同。Microsoft 提供了 dumpbin.exe,它将从库中转储信息。我看到LarryF已经提到了这一点。

For import libraries, run dumpbin.exe -headers foo.liband 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 findstrto 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并将其重定向到输出文件。输出将包含相关 DLL 导出的每个符号的片段。搜索以 开头的行" Symbol name :"。请注意,如果您想要完全匹配,则“符号名称”前后有两个空格。findstr如果您想要更好看的东西,您还可以运行输出以生成符号列表并将其重定向到文本文件:

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

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

另一个选项是使用depends.exe.

回答by LarryF

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.

您的问题不止一件事。我不确定查看 lib 文件是否是解决它的最佳方法,恕我直言...但是,DUMPBIN.exe 可能是您正在寻找的工具。从命令行使用它,但请确保您的路径已设置,或者使用 VS 在您的 VS 开始菜单中为您安装的“Visual Studio 命令提示符”。

回答by Elmue

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:

如果你有一个 DLL 并且想在你的代码中使用它,如果你有一个 DLL__declspec(dllimport)的 DEF 文件,你可以很容易地创建所需的 LIB 文件:

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

which creates mydll.lib

它创建了mydll.lib

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

此命令应在 Visual Studio SDK 命令提示符中运行。

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 namesand ordinalsof all exported functions in a txt file like this:

如果没有 DEF 文件,可以非常轻松地手动编写 DEF 文件:在DependencyWalker( http://www.dependencywalker.com) 中打开 DLL ,选择“另存为”->“带有导入/导出列表的文本”并在 txt 文件中包含所有导出函数的名称序号,如下所示:

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 filewhich has this format:

其余的很快就完成了。创建一个具有以下格式的DEF 文件

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 undecoratecryptic names of C++ exports like

PD:DependencyWalker 甚至可以取消修饰C++ 导出的神秘名称,例如

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

回答by reuns

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

这与 Visual C++ express 9 .lib 一起使用:

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

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

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

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

thank you d.shawley

谢谢 d.shawley

回答by KunMing Xie

open Visual Studio Command Prompt

打开 Visual Studio 命令提示符

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

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