[cfe-dev] Get mangled names C++

Frank Fuchs fk.fuchs at googlemail.com
Thu Jul 15 23:20:01 PDT 2010

Well if I understand your view on it correctly then ... yes that is what I'm
trying to do. However, please allow me to give a more long winded
description of what I want to do. So I have a rather large Qt/C++
application and I want to give it some scripting powers (make its
computational core scriptable from within the application itself). I first
tried to embed some script language (QtScript and Chaiscript), but they did
not convince me in terms of their features and performance (although I must
say that I liked both approaches anyway). Now I want to embed clang into my
application to execute small C++ scripts/ user supplied methods. In the
examples for clang there is an app for that ;), well almost. The
clang-interpreter example takes C/C++ code compiles and runs it. Now the
"only" thing I have to do is to enhance it by exposing my host application
methods to the jitted user supplied scripts. It can be done by either
wrapping all of my methods in extern "C" functions. But this is not what I
If I drop the extern "C" and use C++ headers instead I get error messages
like "LLVM error: program used external function '_Z10testCallerv()' which
could not be resolved". Of course it could not be resolved ... since I was
not able/willing to guess the name-mangling while declaring the the external
function to the clang-interpreter. I used declared "void testCaller()". Now
if I change my declaration to the mangled name it works. I can call C++
methods which reside in the host-application from my scripts. However, I do
not want to mangle all the names of my to-be exposed functions by hand.
There must be a method for that as well - clang must have it already.


PS: @John sorry for the second mail I forgot to include the cfe-list

2010/7/15 John McCall <rjmccall at apple.com>

> On Jul 15, 2010, at 12:56 PM, Frank Fuchs wrote:
> > I'm still figuring how to pass functions from my c++ application (which
> acts as a host to a clang JIT) to the JIT.
> I'm not clear on what you're asking.  As far as I understand, you're using
> clang in-process to generate LLVM IR for C++ source code, which you are then
> going to feed to the JIT.  You're compiling this code in some way such that
> it produces references to global variables/functions, which you'd then like
> to map in the JIT to functions already compiled in your program, and in
> order to perform this mapping you want to re-mangle the global declarations
> you know about to see what names they come out to.  Am I understanding this
> correctly?
> John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100716/aa7cf631/attachment.html>

More information about the cfe-dev mailing list