[LLVMdev] call a extern C function

Samuel Crow samuraileumas at yahoo.com
Thu Jun 3 12:17:23 PDT 2010


Hello Fabio,

You have to make a C wrapper for any C++ code due to "name mangling".  This usually looks something like:

extern "C" int mysum(int a, int b)
{
   return sum(a,b);
}

And then you declare it in the bitcode like this:

declare external i32 mysum(i32, i32)

Then you link both the wrapper and the C++ code in like you would any other linker library, noting the linking order is significant.

Note:  I haven't tested this I may have mistyped something in the commands since I'm typing from memory.

--Sam


>
>From: Fabio Kaminski <fabiokaminski at gmail.com>
>To: llvmdev at cs.uiuc.edu
>Sent: Thu, June 3, 2010 2:07:29 PM
>Subject: [LLVMdev] call a extern C function
>
>How can i interface llvm bitcode with a existent so library...
>
>
>like when you use C prebuilt cos() or sin() ... suppose that i create a sum() in c/c++ compile a .so lib with it
>and call it from "the bitcode" program... how can i do this?
>
>
>Thanks
>
>
>Fabio Kaminski


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100603/67a73a7d/attachment.html>


More information about the llvm-dev mailing list