C++ 使用 dumpbin.exe 的 DLL 函数名称

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

DLL function names using dumpbin.exe

c++windowsvisual-studio-2010dll

提问by TomiL

I have written a .dll library with lots of functions and classes in visual studio 2010. When I look at the content of the file with:

我在 Visual Studio 2010 中编写了一个包含大量函数和类的 .dll 库。当我查看文件内容时:

dumpbin.exe /EXPORTS myDll.dll

I get long function names with some kind of a function location pointer, which looks like this (second entry in .dll):

我得到了带有某种函数位置指针的长函数名称,如下所示(.dll 中的第二个条目):

          2    1 0001100A ?Initialize@codec@codecX@@SANNN@Z = @ILT+5(?Initialize@codec@codecX@@SANNN@Z)

This is somehow hard to read, but I saw "nicer" procedure/function list from other .dll-s, like this:

这有点难以阅读,但我从其他 .dll-s 中看到了“更好”的过程/函数列表,如下所示:

141   8C 00002A08 PogoDbWriteValueProbeInfo

How can I make that .dll list look that way?

我怎样才能让 .dll 列表看起来像那样?

P.S.: my dll source code looks like this:

PS:我的dll源代码是这样的:

namespace codecX
{
   class codec
   {
      public:
      static __declspec(dllexport) double Initialize(double a, double b);
      ...

采纳答案by John K?llén

You need to pull those static member functions into the global address space and then wrap them with extern "C". This will suppress the C++ name mangling and instead give you C name mangling which is less ugly:

您需要将这些静态成员函数拉入全局地址空间,然后用 extern "C" 包装它们。这将抑制 C++ 名称修改,而是为您提供不那么难看的 C 名称修改:

extern "C" __declspec(dllexport) Initialize(double a, double b)
{
    codec::Initialize(a, b);
}

and then remove the __declspec(dllexport) on your static member functions:

然后删除静态成员函数上的 __declspec(dllexport):

class codec
{
    public:
        static double Initialize(double a, double b);
}

回答by bash.d

This is called name-manglingand happens when you compile C++ with a C++-compiler. In order to retain the "humand-readable" names you'll have to use extern "C"when declaring and defining your classes and your functions. i.e.

这称为名称修改,当您使用 C++ 编译器编译 C++ 时会发生这种情况。为了保留extern "C"在声明和定义类和函数时必须使用的“人类可读”名称。IE

extern "C" void myFunction(int, int); 

See hereand also google mixing C and C++.

请参阅此处以及 google mixing C and C++