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
0
votes
3 answers

Is a static variable name, same as function name allowed in C?

I was working on some C-output questions and found the following code: http://ideone.com/O0tQnr In this code , as one can see , inside main , a static variable having same name has been declared. For this I searched on Stack-Overflow and found How…
Dref D
  • 257
  • 2
  • 17
0
votes
1 answer

linking library built with g 2.95.2 to object files built with gcc 4.6

I'm trying to reuse an old static library built with Linux GCC 2.95.2. I'm using a recent compiler (GCC 4.6) from a 32bit Ubuntu distro. The library is written in C++. I have problems linking against the functions which are encapsulated in…
0
votes
0 answers

Can I rewrite this boost interprocess set of typedefs and avoid the name length exceeded warning in vc 2008?

Is this warning about name length always harmless? If not, how do I know if I'm in trouble? One lovely thing in C++ type manging is when name length is exceeded. The linked question shows how to turn it off. I am using Visual C++ 2008 with Boost…
Warren P
  • 65,725
  • 40
  • 181
  • 316
0
votes
2 answers

How variables defined in __init__ of Thread module get renamed to _Thread_

I am going through the code of threading module(/lib/threading.py) on Active python 2.7.2 32 bit for Windows. In the __init__ function of the class Thread, there are many variables defined: self.__target = target self.__name = str(name…
GodMan
  • 2,561
  • 2
  • 24
  • 40
0
votes
2 answers

Intel Visual Fortran Compiler name mangling, is my compiler just being crazy?

I am using Intel Visual Fortran Composer XE 2011 to build my Fortran project in MS Visual Studio 2008. I am getting linker errors: LNK2019 unresolved external symbol. I did a dumpbin on my obj files and all of my symbols (under CVF calling…
0
votes
2 answers

How to use audiere dll with MinGW

I am building a project using wxWidgets compiled with MinGW g++ compiler. I was also using a component of the wxWidgets platform to play mp3 sound clips, but it has been unreliable so I went looking for another solution. I found audiere and…
Jim
  • 55
  • 1
  • 6
0
votes
1 answer

Get name mangling when I try to use exceptions [CodeBlocks, C++]

I am trying to use exceptions for the first time but even though it is quite a simple example I just cannot get it to compile, I have looked at several examples and tried coding it in many, many different ways but I am still not even sure exactly…
Beetroot
  • 701
  • 6
  • 12
0
votes
0 answers

Exception - EntryPoint for not found in the dll

I've created a C++ DLL which I import to C# application to re-use a function. the function code in C++ is static bool IsDisplayDeviceAttached(char *Arg1[]) When I use DllImport as below in C# program, [DllImport("DllName",…
-1
votes
1 answer

name mangling in MinGW , plug-in system c++

I am learning plugin system in C++ on the windows by using MinGW g++ compiler. the compiler version is : C:\SAVVY\src>g++ --version g++ (MinGW.org GCC Build-2) 9.2.0 And I downloaded the source code from…
-1
votes
1 answer

"Blind" demangling, with precise semantics and a cherry on top

There are lots of questions on SO about name mangling and demangling vis-a-vis the ABI used by gcc and clang. Many of the demangling questions involve trying to get at the semantics embedded in the mangling grammar, as in "Extracting class from…
BrianTheLion
  • 2,618
  • 2
  • 29
  • 46
-1
votes
1 answer

Unresolved external class member when linking static lib from dynamic dll

MS Visual Studio 2008. This seems to be a name mangling issue, but I can't find the right search terms to come up with an answer. I have a dynamic lib that has a class in it, which is using a logging class from a static logging library. The dynamic…
JoeFish
  • 3,009
  • 1
  • 18
  • 23
-1
votes
3 answers

How does the C compiler handles different main function definitions?

The main question is: How does the C compiler handles multiple definitions for the function main in different source codes? Like: void main(void) int main(void) int main(int argc, char *argv[]) ... I don't know if this has something to do with name…
joaopauloribeiro
  • 397
  • 2
  • 10
-1
votes
1 answer

Python: How can I defeat a lock in mangled variable which uses a special method?

In python, one is able to use special methods to achieve something similar to operator overloading in C++ by defining a special method for __setattr__. I have seen some coders use this to create a read-only lock using a mangled variable name. That's…
James Shewey
  • 260
  • 2
  • 19
-1
votes
1 answer

How to force compiler to mangle C names to C++ names

I have .obj with function that has everything it needs to be linked as C++ member function. Problem is, it's in C and thus the class using it expects something uglier than it's normal name. So I figure this can be done in only 2 ways: either mangle…
Pyjong
  • 3,095
  • 4
  • 32
  • 50
-4
votes
2 answers

Why can my my C++ program correctly linked when I replace libstdc++ with libgcc

Currently I read an article about name mangling on wikipeida(link). In that article, I learn that the common extern "C" idiom is used to protect those C code in C++ source file from being mangled, which make those source code incompatible to be…
walkerlala
  • 1,599
  • 1
  • 19
  • 32
1 2 3
21
22