Re: Way to look up a C++ function name?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/14/2011 01:14 PM, david.hagood@xxxxxxxxx wrote:
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?

It would probably be much easier and more reliable to wrap these function declaration in 'extern "C"' wrappers to give them C calling semantics... although that would impact the types of parameter arguments and return values they could accept and return.


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;
}




--
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
Jabber: kfleming@xxxxxxxxxx | SIP: kpfleming@xxxxxxxxxx | Skype: kpfleming
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at www.digium.com & www.asterisk.org


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux