C++ DLL 导出:修饰/损坏的名称 [英] C++ DLL Export: Decorated/Mangled names

查看:22
本文介绍了C++ DLL 导出:修饰/损坏的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用模块定义文件 (MyDLL.def) 创建基本的 C++ DLL 并导出名称.编译后,我使用 dumpbin.exe 检查导出的函数名称我希望看到:

Created basic C++ DLL and exported names using Module Definition file (MyDLL.def). After compilation I check the exported function names using dumpbin.exe I expect to see:

SomeFunction

但我看到的是这个:

SomeFunction = SomeFunction@@@23mangledstuff#@@@@

为什么?

导出的函数看起来没有修饰(特别是与不使用 Module Def 文件相比),但是其他东西怎么了?

The exported function appears undecorated (especially compared to not using the Module Def file), but what's up with the other stuff?

如果我对来自任何商业应用程序的 DLL 使用 dumpbin.exe,你会得到干净的:

If I use dumpbin.exe against a DLL from any commercial application, you get the clean:

SomeFunction

没有别的...

我还尝试删除模块定义并使用C"样式的导出来导出名称,即:

I also tried removing the Module Definition and exporting the names using the "C" style of export, namely:

extern "C" void __declspec(dllexport) SomeFunction();

(仅使用externC"并没有创建导出函数)

(Simply using "extern "C" did not create an exported function)

但是,这仍然会创建相同的输出,即:

However, this still creates the same output, namely:

SomeFunction = SomeFunction@@@23mangledstuff#@@@@

我还尝试了 #define dllexport __declspec(dllexport) 选项并创建了一个没有问题的 LIB.但是,我不想向在 C# 应用程序中使用 DLL 的人提供 LIB 文件.

I also tried the #define dllexport __declspec(dllexport) option and created a LIB with no problem. However, I don't want to have to provide a LIB file to people using the DLL in their C# application.

这是一个普通的 C++ DLL(非托管代码),用 C++ 编译,只有一个简单的头文件和代码.如果没有 Module Def ,我的导出函数会被破坏(我可以创建一个静态库并使用 LIB 没问题.我试图避免这种情况).如果我使用 extern "C" __declspec(dllexport) OR 一个模块定义,我得到的似乎是一个未修饰的函数名......唯一的问题是它被遵循由="和看起来像函数的装饰版本的东西.我想摆脱="之后的东西 - 或者至少了解它为什么在那里.

It's a plain vanilla C++ DLL (unmanaged code), compiled with C++ nothing but a simple header and code. Without Module Def I get mangled exported functions (I can create a static library and use the LIB no problem. I'm trying to avoid that). If I use extern "C" __declspec(dllexport) OR a Module Definition I get what appears to be an undecorated function name... the only problem is that it is followed by an "=" and what looks like a decorated version of the function. I want to get rid of the stuff after the "=" - or at least understand why it is there.

就目前而言,我非常确定我可以使用 P/Invoke 从 C# 调用该函数……我只想避免="末尾的垃圾.

As it stands, I'm pretty certain that I can call the function from C# using a P/Invoke... I just want to avoid that junk at the end of the "=".

我愿意接受有关如何更改项目/编译器设置的建议,但我只是使用了标准的 Visual Studio DLL 模板 - 没什么特别的.

I'm open to suggestions on how to change the project/compiler settings, but I just used the standard Visual Studio DLL template - nothing special.

推荐答案

您可以通过关闭调试信息生成来获得您想要的.项目 + 属性、链接器、调试、生成调试信息 = 否.

You can get what you want by turning off debug info generation. Project + Properties, Linker, Debugging, Generate Debug Info = No.

当然,您只想为发布版本执行此操作.选项已经设置为这种方式.

Naturally, you only want to do this for the Release build. Where the option is already set that way.

这篇关于C++ DLL 导出:修饰/损坏的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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