.def 文件 C/C++ DLL
我不明白将 .def 文件与 DLL 一起使用的意义.
I am not understanding the point of using .def files with DLLs.
它似乎取代了在您的 DLL 代码中使用显式导出的需要(即显式 __declspec(dllexport)),但是我无法在不使用这些时生成 lib 文件,然后在使用 DLL 时创建链接器问题.
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) 语法的替代方案,具有能够显式指定导出的序数的额外好处职能.如果您仅按序数导出某些函数,这会很有用,这不会显示有关函数本身的太多信息(例如:许多操作系统内部 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.
相关文章