Questions tagged [name-mangling]

Name-mangling is a technique used by compilers (mainly C++ compilers) to encode information in strings that can be supported by linkers designed to handle C code.

Questions relating to the schemes used for name mangling, linking problems in the face of mangling, or the tools used to decode mangled names (like c++filt or dem) are appropriate for this tag.

In C++, name mangling is used to encode things like the symbol's namespace and/or function signature.

For example, given this C++ code:

namespace Foo {
namespace Bar {
    class A {
        public:
            A();
            ~A();
    };
}

int f(int i)
{
    Bar::A a;
}

int f(double d)
{
    Bar::A a;
}

}

the g++ compiler on a Linux box might generate the following "mangled" names for the 2 overloads of f() and A's constructor and destructor:

  • _ZN3Foo1fEd
  • _ZN3Foo1fEi
  • _ZN3Foo3Bar1AC1Ev
  • _ZN3Foo3Bar1AD1Ev

Using a tool like c++filt, we can decode these names:

$ echo _ZN3Foo1fEd | c++filt
Foo::f(double) 

$ echo _ZN3Foo3Bar1AC1Ev | c++filt
Foo::Bar::A::A() 

Of course, if you're not using g++ on Linux, the mangled form for your symbols may (likely WILL) be different. (The C++ FAQ lite subtly suggests that if two C++ compilers have different ABIs, even in small details, then they should intentionally have different name mangling schemes, so that things break in an obvious way and not a subtle way.)

316 questions
5
votes
1 answer

Linking to a .dll file without the .lib

I need to rewrite some Delphi code to C++ and we need to link to the dynamic library TMLComm2004.dll. It turns out that we don't have any .lib file so we decided to generate it, using the following command lines: dumpbin /EXPORTS…
InsideLoop
  • 6,063
  • 2
  • 28
  • 55
5
votes
1 answer

clang mangled names varies over time

We have encountered something, which about I don't find any documentation. It seems, that there are a lot of class members, etc. which gets different mangled names over time. So in one day, the compilation gives it, for…
newhouse
  • 1,152
  • 1
  • 10
  • 27
5
votes
1 answer

C++ get the mangled names of a function/method

Hi I need to determine the mangled name of a function from within an c++ app itself. Is there any equivalent to the __FUNCDNAME__ macro in g++ ?
FFox
  • 1,550
  • 2
  • 17
  • 26
5
votes
1 answer

Template which prints the name of the given type

I would like to print the name of a type for debugging purposes, so I've created a function which does the trick (in fact, I borrowed it from another SO answer, which I cannot found now), the function looks like this: template
PaperBirdMaster
  • 12,806
  • 9
  • 48
  • 94
5
votes
1 answer

Is this a mangling bug in Solaris Studio?

The source (at the end of the question) will provoke what I believe is a mangling error on Solaris Studio (and not on other compilers). The error message was reformatted with new lines for clarity: "overload.cpp", line 44:…
paercebal
  • 81,378
  • 38
  • 130
  • 159
5
votes
5 answers

Calling C++ function from C without using extern "C"

Is it possible to call a function in a C++ DLL from C code? The function is not declared extern "C". An ugly platform dependent hack that only works with Visual Studio is fine. Calling conventions should not be a major issue, but how do I deal with…
Johan Råde
  • 20,480
  • 21
  • 73
  • 110
5
votes
1 answer

g++: How to unmangle exported symbols

I'm trying to compile a Java library that uses JNI. When I start the program, I see a crash with an UnsatisfiedLinkError, which says that a particular method could not be found in the DLL. On closer inspection, I found out that g++, which I use for…
python dude
  • 7,980
  • 11
  • 40
  • 53
5
votes
1 answer

Is there an Microsoft VC++ equivalent to __cxa_demangle in gcc?

I have tried UnDecorateSymbolName(). For example: #include #include #include #pragma comment(lib,"dbghelp.lib") int main(int argc, _TCHAR* argv[]) { TCHAR…
Alan Yang
  • 65
  • 4
5
votes
6 answers

C++ : Finding out decorated names

How can I find out the decorated name that will be asigned to each method name ? I'm trying to find out what the decorated name is , so that I may export it , in a DLL .
Vhaerun
  • 12,806
  • 16
  • 39
  • 38
5
votes
2 answers

unresolved external symbol due to name mangling

I am facing linker error for a XERCES function while upgrading it from 2.6 to 2.8 unresolved external symbol (?resolveEntity@HandlerBase@xercesc_2_8@@UAEPAVInputSource@2@QBG0@Z) I checked the xerces-c_2.8.lib and found that name lib is bit…
NoName
  • 106
  • 1
  • 5
5
votes
4 answers

Using C++ mangled functions from C

I have a .lib file, source code of which I don't have. I need an exported function from it, but I'm writing in C, and the function is C++ name-mangled. I can't write extern "C", because I don't have the source code. How do I link mangled function…
Triang3l
  • 1,230
  • 9
  • 29
4
votes
4 answers

Can't prevent name mangling

I am trying to build a dll written in C and which will be imported by other programs also written in C. So all the function that the dll is exporting are defined in a .dll "without __declspec(dllexport)" (intentional). I have defined a .def file…
Kartik Rustagi
  • 669
  • 2
  • 8
  • 16
4
votes
2 answers

Using a Delphi DLL in C++ - How to properly call functions?

At work one brand of battery cyclers we are using has a proprietarily encodd data format which I would like to directly read in my scripts instead of the much larger ASCII version of the data. The manufacturer provided a DLL (no library or header)…
4
votes
2 answers

Compiler agnostic fortran name mangling function

I am dynamically linking to a fortran static object and need to be able (at run time) to take the name of the fortran function (which is a C++ string) and name mangle it appropriately for the compiler. Is there any pre-built function that would…
V.S.
  • 2,924
  • 4
  • 32
  • 43
4
votes
1 answer

How to access assembly language symbols without a leading _ from C on 6502 (cc65)

I'm writing some code in 6502 assembly language using cc65. Because I'm living in 2022 and not 1979 and have access to a development machine that is a million times more powerful than the target platform, I'm writing unit tests for the assembly…
Willis Blackburn
  • 8,068
  • 19
  • 36