How can I get a distorted function name from a C ++ program?
For example, suppose I have a heading:
#ifndef INTERFACE_H
#define INTERFACE_H
typedef void (*FooFunc)(int x, int y, double z, ...more complicated stuff...);
void foo(int x, int y, double z, ...more complicated stuff...);
#endif
and I have a client program that can load plugins that implement the interface:
#include "interface.h"
void call_plugin(so_filename)
{
void *lib = dlopen(so_filename, ...);
static const char *mangled_name = get_mangled_name(foo);
FooFunc func = (FooFunc)dlsym(lib, mangled_name);
func(x, y, z, ...);
dlclose(lib);
}
How to write a function get_mangled_nameto calculate the distorted function name fooand return it as a string?
One method that comes to mind is to compile interface.oand use nm -A interface.o | grep footo get the changed name, and then copy and paste it as a string with hard code in client.h, but this seems like the wrong approach.
, , interface.h C-, ++ -, C, ++, , .
Edit
, . , ++ , , ++.