.def文件C / C ++ DLL [英] .def files C/C++ DLLs

查看:174
本文介绍了.def文件C / C ++ DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白使用DLL的.def文件的点。

I am not understanding the point of using .def files with DLLs.

似乎它取代了在DLL代码中使用显式导出的需要(即。显式__declspec(dllexport))然而,我不能在不使用这些然后在使用DLL时创建链接器问题时生成一个lib文件。

It seems that it replaces the need to use explicit exports within your DLL code (ie. explicit __declspec(dllexport)) however I am unable to generate a lib file when not using these which then creates linker issues later when using the DLL.

那么当与客户端应用程序链接时,如何使用.defs,它们是否替换了使用头文件或.lib文件的需要?

So how do you use .defs when linking with the client application, do they replace the need to use a header or .lib file?

推荐答案

我的理解是,.def文件提供了__declspec(dllexport)语法的替代方法,另外还有一个好处是能够明确指定导出功能。如果您仅通过ordinal导出一些函数,这并不能显示与函数本身相关的信息(例如:许多操作系统内部DLL的导出函数只能由序数),这可能很有用。

My understanding is that .def files provide an alternative to the __declspec(dllexport) syntax, with the additional benefit of being able to explicitly specify the ordinals of the exported functions. This can be useful if you export some functions only by ordinal, which doesn't reveal as much information about the function itself (eg: many of the OS internal DLL's export functions only by ordinal).

请参阅参考页面

请注意.def文件中的名称必须与二进制文件中的名称相匹配。所以如果你使用C或C ++与'extern'C{...}',名字不会被破坏;否则您必须使用正确的已知名称来编译用于生成DLL的特定版本。 __declspec()函数全部自动执行。

Note that the names in the .def file must match the names in the binary. So if you using C or C++ with 'extern "C" { ... }', the names will not be mangled; otherwise you must use the correct mangled names for the specific version of the compiler used to generate the DLL. The __declspec() function does this all automatically.

这篇关于.def文件C / C ++ DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆