name-mangling

How do I stop name-mangling of my DLL's exported function?

泪湿孤枕 提交于 2019-11-26 18:53:10
I'm trying to create a DLL that exports a function called "GetName". I'd like other code to be able to call this function without having to know the mangled function name. My header file looks like this: #ifdef __cplusplus #define EXPORT extern "C" __declspec (dllexport) #else #define EXPORT __declspec (dllexport) #endif EXPORT TCHAR * CALLBACK GetName(); My code looks like this: #include <windows.h> #include "PluginOne.h" int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved) { return TRUE ; } EXPORT TCHAR * CALLBACK GetName() { return TEXT("Test Name"); } When I build,

Getting mangled name from demangled name

橙三吉。 提交于 2019-11-26 18:44:30
Is there any way to get back the mangled name from demangled name in g++. For example , I have the demangled name func(char*, int) , what should I do to get the mangled name i.e _Z4funcPci back? My question is g++ specific. You can simply use g++ to compile an empty function with the signature you require and extract the name from that. For example: echo "int f1(char *, int) {} " | g++ -x c++ -S - -o- | grep "^_.*:$" | sed -e 's/:$//' gives output _Z2f1Pci which is I think what you require. Make sure that you include any relevant header files as they will affect the way the symbols are mangled

What is name mangling, and how does it work?

99封情书 提交于 2019-11-26 16:12:07
Please explain what is name mangling, how it works, what problem it solves, and in which contexts and languages is used. Name mangling strategies (e.g. what name is chosen by the compiler and why) a plus. In the programming language of your choice, if an identifier is exported from a separately compiled unit, it needs a name by which it is known at link time. Name mangling solves the problem of overloaded identifiers in programming languages. (An identifier is "overloaded" if the same name is used in more than one context or with more than one meaning.) Some examples: In C++, function or

Scala: How do I dynamically instantiate an object and invoke a method using reflection?

蹲街弑〆低调 提交于 2019-11-26 11:50:08
问题 In Scala, what\'s the best way to dynamically instantiate an object and invoke a method using reflection? I would like to do Scala-equivalent of the following Java code: Class class = Class.forName(\"Foo\"); Object foo = class.newInstance(); Method method = class.getMethod(\"hello\", null); method.invoke(foo, null); In the above code, both the class name and the method name are passed in dynamically. The above Java mechanism could probably be used for Foo and hello() , but the Scala types don

What is the benefit of private name mangling in Python?

情到浓时终转凉″ 提交于 2019-11-26 10:59:23
问题 Python provides private name mangling for class methods and attributes. Are there any concrete cases where this feature is required, or is it just a carry over from Java and C++? Please describe a use case where Python name mangling should be used, if any? Also, I\'m not interested in the case where the author is merely trying to prevent accidental external attribute access. I believe this use case is not aligned with the Python programming model. 回答1: It's partly to prevent accidental

Getting mangled name from demangled name

老子叫甜甜 提交于 2019-11-26 06:33:47
问题 Is there any way to get back the mangled name from demangled name in g++. For example , I have the demangled name func(char*, int) , what should I do to get the mangled name i.e _Z4funcPci back? My question is g++ specific. 回答1: You can simply use g++ to compile an empty function with the signature you require and extract the name from that. For example: echo "int f1(char *, int) {} " | g++ -x c++ -S - -o- | grep "^_.*:$" | sed -e 's/:$//' gives output _Z2f1Pci which is I think what you

Why do we need extern “C”{ #include <foo.h> } in C++?

此生再无相见时 提交于 2019-11-26 02:57:19
Why do we need to use: extern "C" { #include <foo.h> } Specifically: When should we use it? What is happening at the compiler/linker level that requires us to use it? How in terms of compilation/linking does this solve the problems which require us to use it? C and C++ are superficially similar, but each compiles into a very different set of code. When you include a header file with a C++ compiler, the compiler is expecting C++ code. If, however, it is a C header, then the compiler expects the data contained in the header file to be compiled to a certain format—the C++ 'ABI', or 'Application

Unmangling the result of std::type_info::name

ⅰ亾dé卋堺 提交于 2019-11-26 01:39:41
问题 I\'m currently working on some logging code that supposed to - among other things - print information about the calling function. This should be relatively easy, standard C++ has a type_info class. This contains the name of the typeid\'d class/function/etc. but it\'s mangled. It\'s not very useful. I.e. typeid(std::vector<int>).name() returns St6vectorIiSaIiEE . Is there a way to produce something useful from this? Like std::vector<int> for the above example. If it only works for non-template

How do I list the symbols in a .so file

ε祈祈猫儿з 提交于 2019-11-26 01:36:50
问题 How do I list the symbols being exported from a .so file? If possible, I\'d also like to know their source (e.g. if they are pulled in from a static library). I\'m using gcc 4.0.2, if that makes a difference. 回答1: The standard tool for listing symbols is nm , you can use it simply like this: nm -g yourLib.so If you want to see symbols of a C++ library, add the "-C" option which demangle the symbols (it's far more readable demangled). nm -gC yourLib.so If your .so file is in elf format, you

Why do we need extern “C”{ #include <foo.h> } in C++?

南楼画角 提交于 2019-11-26 01:12:33
问题 Why do we need to use: extern \"C\" { #include <foo.h> } Specifically: When should we use it? What is happening at the compiler/linker level that requires us to use it? How in terms of compilation/linking does this solve the problems which require us to use it? 回答1: C and C++ are superficially similar, but each compiles into a very different set of code. When you include a header file with a C++ compiler, the compiler is expecting C++ code. If, however, it is a C header, then the compiler