在 Visual Studio 中自动生成 DLL .DEF 文件?
有没有办法在 Visual Studio 中自动生成 DLL 的 DEF 文件?我以前总是手动创建它们,但一定有一种更简单的方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在这里找到了一个为您生成 .DEF 文件的地方: expdef - def 文件生成器< /a>
这非常有效,除了函数和符号的方法名称之外,您还可以生成一个选项列表。
I have found a place to generate the .DEF file for you here: 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.
简而言之:编写适合您需求的脚本。我在某些地方创建了一个小型 Perl 脚本,用于从现有 DLL 创建一个
.def
文件,然后将该文件用于创建导入库 (.lib
) 从中。没有读取即用工具可以为您执行此操作的原因是,所涉及的工具都无法猜测或以某种心灵感应方式确定您想要导出哪些函数、变量、常量或类以及以哪些名称导出。
您可能知道,模块定义文件允许您更改内部名称在导出表中的显示方式,允许按序号(而不是名称)或按名称和序号导出。当然,它们还允许多次导出一个函数(例如,由于遗留支持目的而使用旧名称,而由于现在遵循某种约定而使用新名称)。
另请参阅此问题。您会注意到答案还涉及自定义脚本。在这种情况下,要求显然只是分解和导出任何和所有非静态函数的名称。
Simply put: write a script that suits your needs. I for one created a small Perl script at some to create a
.def
file from an existing DLL that would then be used to create an import library (.lib
) from it.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.
请参阅此处演示项目的答案:
https://stackoverflow.com/a/64302521/2338477
我已经包含了 python 脚本从静态库生成 .def 文件,但不幸的是它不适用于变量/数据。
See answer with demo project in here:
https://stackoverflow.com/a/64302521/2338477
I have included python script to generate .def file from static library, but that unfortunately does not work with variables / data.