visual-studio 在 Visual Studio 中自动生成 DLL .DEF 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2178220/
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 11:29:38  来源:igfitidea点击:

Automatically generate a DLL .DEF file in Visual Studio?

visual-studiodlldllexport

提问by Adam Haile

Is there any way to automatically generate the DEF file for a DLL in Visual Studio? I've always just manually created them before, but there's gotta be an easier way.

有没有办法在 Visual Studio 中为 DLL 自动生成 DEF 文件?我以前总是手动创建它们,但必须有更简单的方法。

回答by user2577497

I have found a place to generate the .DEF file for you here: expdef - def file generator

我在这里找到了一个可以为您生成 .DEF 文件的地方:expdef - def file generator

This works amazing and has a list of options you could also generate besides the method names of the functions and symbols.

这很有效,并且有一个选项列表,除了函数和符号的方法名称之外,您还可以生成它。

回答by 0xC0000022L

Simply put: write a script that suits your needs. I for one created a small Perl script at some to create a .deffile froman existing DLL that would then be used to create an import library (.lib) from it.

简单地说:编写适合您需求的脚本。我在某个地方创建了一个小的 Perl 脚本,用于现有的 DLL创建一个.def文件,然后该文件将用于从中创建导入库 ( )。.lib

The reason there is no read-to-use tool that does it for you is because none of the tools involved can guess or somehow telepathically determine which functions or variables or constants or classes you want to export and under which names.

没有为您执行此操作的即用型工具的原因是,所涉及的任何工具都无法猜测或以某种方式通过心灵感应确定您要导出哪些函数或变量或常量或类以及使用哪些名称。

As you may know module definition files allow you to alter how an internal name appears in the export table, allow to export by ordinal (instead of name) or by name and ordinal. Of course they also allow to export a function multiple times (e.g. an old name due to legacy support purposes and a newer one because it follows some convention now).

您可能知道模块定义文件允许您更改内部名称在导出表中的显示方式,允许按序号(而不是名称)或按名称和序号导出。当然,它们也允许多次导出一个函数(例如,一个旧的名称由于遗留支持的目的和一个新的,因为它现在遵循一些约定)。

Also see this question. You will notice that the answer also involves a custom script. In this case the requirement is apparently only to demangle and export the names of any and all non-static functions.

另请参阅此问题。您会注意到答案还涉及自定义脚本。在这种情况下,要求显然只是对任何和所有非静态函数的名称进行解码和导出。