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?


Fabio Kaminski

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.