This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Way to look up a C++ function name?


I have a chunk of code that loads a shared library + a file containing a
list of functions in that library (it's a scripting language parser, for
the curious - the functions implement verbs in the scripting language).

This works fine with C functions, as the dlsym() function can find the
function name in the shared lib. However, with C++ functions it won't work
unless you pass the mangled function name in to dlsym. So I would either
have to put the mangled name in my function definition file (and that
would change based upon the specific C++ compiler used - I'd like to
support both GCC and MSVC if possible). Putting aside the issue of
different compilers for the moment, is there a way to, given a string such
as "void foo(int &)" convert that to the mangled name GCC would emit, and
do so at run time?

e.g.

int my_example(vector<string> names)
{
   for (vector<string>::iterator i = names.begin();i != names.end(); ++i)
     std::cout << "Function " << *i << " mangles to " <<
some_magic_libgcc_function((*i).c_str()) << std::endl;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]